Official Blog of Azilen

The Techie Explorations

How to Create Portlet Application Using OSGi in Liferay 7?

Being a programmer, you must have faced a situation where you had to start over from scratch every time you start any new project. You have to write not only the code for project build but also the underlying codes that support the project. This makes it a tiring task. So to eliminate this redundancy, there is a platform that offers a baseline set of features that would help in giving a head start on the entire repetitive code which is termed as Liferay Portal. Liferay Portal offers the developers a platform for building web apps, mobile apps and web services quickly using the features and frameworks designed for the rapid development and ease of use. It also offers some of the best tools to make the programming easier among which Blade CLI is one of the major tools.

Let us have a deeper understanding on what is Blade CLI and how it can be used with any IDE or development environment.

What is Blade CLI?

Blade CLI is a command line tool that is bootstrapped on to a Gradle based environment used for building Liferay 7.0 modules. It is one of the easiest ways for Liferay developers to create new Liferay portal solutions and modules. You can simply download blade tools JAR and once you’ve obtained the Blade Tools JAR, you can install Blade Tools through the Java Package Manager (JPM).

Using JAVA Package Manager (JPM) To Download Blade Tools:

1) Install JAVA Package Manager(JPM) from here, if you don’t have installed in your machine yet

2) Once JPM is installed, we need to download com.liferay.blade.cli.jar from here.

3) Next, we can install Blade tools from downloaded JAR with the use of below command.

4) Alternate command to install blade tools.

Verifying Blade CLI installation:

1) Verify your installation by writing “blade” command in command prompt. We can see below list of MAIN OPTIONS and available sub-commands for the installed blade tools.


2) We have installed Blade tools, now let’s understand its 2 important command: blade create and blade deploy

3) To understand how to use blade create, enter blade create command into terminal. Below is output that terminal produces.

4) We need to make sure that our module is built before we execute blade deploy command as this command will be used to deploy application in Liferay.

Creating first Liferay Application with Blade Tools:

1) Let’s create liferay portlet application with the use of blade tools and MVC architecture. We will create MVC portlet here. In order to create MVC portlet, we have to run below command.

2) Above command will create MVC portlet, and create folder structure as shown below.

3) We are now ready to build our portlet. Run gradle build command to build your portlet.

4) If you get build successful message in your above step then we are ready to deploy our application on liferay. Before deploying our application in liferay we need to install remote agent with the use of blade agent install –l <Liferay home path> command. Below message will be displayed on screen if agent has successfully installed.

5) Blade needs gradle wrapper files in your module.

To install gradle wrapper, we need to add above lines in our build.gradle file and then we can run gradle wrapper command from command prompt.

6) Once wrapper is installed, we can run blade deploy command from command prompt to deploy our application.

7) It will copy jar file into our <module directory>/build/libs and deploy your application in liferay

8) Login to your liferay instance and you can add your new application from applications.

This is how a portlet application can be created using OSGI modular framework. As Liferay was written by developers for the developers to get the work done faster and easily, the Blade CLI tools does the same while making programming easy and convenient.

Leave a reply