To create anew portlet in liferay we first need to install the Blade CLI and then we need to create a new Liferay Workspace. Please go through the above tutorials if you haven't yet installed Blade CLI and created Liferay Workspace.
How to Create and Deploy a new Portlet using Blade
To create modules using blade is quite simple. It is as good as creating the portlets using the command line tool of liferay SDK. To create the modules using the Blade you need to first install Blade. For knowing how to install blade please refer to my previous blog post on blade-installation-for-liferay7.
Once you had installed blade on your machine, you need to navigate to the directory where you need to create the portlet.
To create a module/portlet using blade, following the minimal command
blade create [OPTIONS] <NAME>
blade create My-Sample-Portlet
The above command will create a new portlet with default configurations and a controller with the name MySamplePortlet.
The above command will create a new project in the current with the name my-mvc-portlet-project. Because we are using the template mvcportlet this project will be created as a MVCPortlet Project, and the module will be having the Controller which will extend the MVCPortlet.java. The controller class will be in the package com.liferay.docs.mvcportlet.portlet and the name of the controller will be MyMvcPortlet.
Once the above command is punched in cmd, the below screen will come up. This will initially download the Gradel distribution as the build process will be using gradle.
Once completed the below screen will come up with a message that Create the project my-mvc-portlet-project using the mvcportlet template in <DIRECTORY>
Once created we can import the above project into eclipse using the import of eclipse. Click on Import->Liferay Module Projects
Click on the browse and provide the location of project.
Once imported the project will come up in the below shown structure. This verifies that the project has been created successfully.
Blade deploy
Now the next step is how to deploy the module/portlet into liferay. To do that it is easy, we just need to write the blade deploy command. This will search for the running instance of liferay on that machineand will deploy this module into the same.
blade deploy
blade deploy <PORT> - Will deploy in a liferay instance running on an specific port.
Below the image that shows that the Build is successfull and Portlet/module has been Started.
We can also see in the eclipse Console as shown below that the portlet/module is available for use. Here STARTED means available for use.
How to create portlet Using Blade in Liferay7
How to deploy portlet in Liferay7
For
more details on the above topic please go through the below video on myyoutube channel.
Blade is used to create the OSGI modules for liferay. Though liferay has provided the module support by the plugin SDK, but the modules created by blade can be used with any IDE or any other development environment. Blade is a command line tool that is used to create the modules for liferay 7.
The best and easiest way to install the blade is using the JAR file. This JAR can be installed using the JPM (JAVA PACKAGE MANAGER)
How to install Blade for Liferay7
Download the biz.aQute.jpm.run.jar JAR and save it in a directory. Let's say C:\Download
Now run the following command in command prompt c:\Downloads>java -jar biz.aQute.jpm.run.jar-g init
It will get install the JPM in C:\JPM4J
Now run this command. C:\JPM4J\bin> jpm platform path -a . This will add the jpm command in ENV-User Variable so that this can be used in commad prompt.
Now add the C:\JPM4J\bin in system variable PATH
Run the following command from C:\JPM4J\bin, so that the Blade can be installed, C:\JPM4J\bin>jpm install -f https://liferay-test-01.ci.cloudbees.com/job/liferay-blade-cli/lastSuccessfulBuild/artifact/com.liferay.blade.cli/generated/com.liferay.blade.cli.jar
Once the Blade is installed successfully you can verify the same by running the blade version command.
Blade provides a set of command line tools that can be used to create, update, deploy, start etc a module.
version-- Display Blade version.
create-- Creates a new Liferay module project from available templates.
deploy-- Builds and deploy the module for Liferay framework. It detects the current running liferay7 instance and deploy the module in the same.
gw-- Executes the Gradle commands using the Gradle Wrapper, if found, else it would not be executed.
init-- Initializes a new Liferay Workspace.
install-- Installs a bundle into Liferay’s module framework.
help-- Gives help on a specific command.
server-- Starts or stops server defined by your Liferay project.
open-- Opens or imports a file or project in Liferay IDE.
migrateTheme-- Migrates a Plugins SDK theme to a new workspace theme project, this is useful when you are migrating the themes.
samples-- Will create a sample project of Blade.
update-- Will update the Blade to current version of Blade
For
more details on the above topic please go through the below video on myyoutube channel.
To install liferay on windows below are the required steps -:
But first the minimum requirements for the setup
Liferay Eclipse IDE 3 (Extract to a location)
JAVA 8 (Won't work below java 8)
Mysql 5.6+
Liferay Portal (Extract to a location)
In the first step we are going to check if JAVA-8 is installed on the system.
In the next step configure the Eclipse IDE as usual, by giving up the workspcae name. Once done with this step we will create a new servre. Open Eclispe and click on the create new server. Now select the Lifery 7x option.
You will get the above screen, now select Next this will produce the below screen. Click on the browse button and select the portal directory in which you had extracted the liferay portal.
In most of the cases the old JDK/JRE will be installed on the system. And the eclipse will be probably starting using the same. Also if you see the eclipse uses JRE by default. So to overcome that you have to define a new JDK/JRE that points to JAVA8. To do that click on the installed JRE as shown in the below figure. Now select the path to JDK of java 8. Generally it is C:\Program Files\Java\jdk1.8.0_101 for Windows.
Once done with the above steps you will see that a new server has been created in the servers tab. Click on the start button and wait for it to start.
Once the server is up you can see the above screen in eclipse and below in the browser.
Liferay by default uses the Hypersonic database, we need to change it for further development. So to change it click on the Change button on the above screen. Post that the below screen will pop up. By default liferay users the lportal database name. So you need to create a new database with the name lportal. Now insert the username and password of the database in the form and click save.
Once the values are saved these configurations will be saved in the portal-setup-wizard.properties in the LIFERAY_HOME.
Now in order to make the database change effect we need to restart the portal.
Restart the portal, while restarting Liferay will fill up the required database with the sample data and your portal will be up. Once the portal is up the below home page will be visible.
Congratulations you have installed liferay 7 successfully :)
For
more details on the above topic please go through the below video on myyou tubechannel.