Liferay Hello World Portlet | How To Create Portlet Using Liferay Plugins SDK?
In this post we will create and deploy a simple "hello world" portlet using the Liferay Plugins SDK using step by step guide as follows.
Creating portlets with the Plugins SDK is extremely simple. There is a portlets folder inside of the Plugins SDK folder. This is where your portlet projects will reside. To create a new portlet, first decide what its name is going to be. You need both a project name (without spaces) and a display name (which can have spaces).
When you have decided on your portlet's name, you are ready to create the project. For the greeting portlet, the project name is “hello-word”, and the portlet title is “Hello World”. Navigate to the portlets directory in the terminal and enter the following command
For Linux, Unix and Mac OS X:
For all windows platforms:
You should get a BUILD SUCCESSFUL message from Ant, and there will now be a new folder inside of the portlets folder in your Plugins SDK. This folder is your new portlet project. This is where you will be implementing your own functionality. Notice that the Plugins SDK automatically appends “-portlet” to the project name when creating this folder. In this case you can find directory "hello-word-portlet" in side portlets directory
Deploying the portlet on Liferay Portal
Select the Sample category, and then click Add next to Hello World. Your portlet should appear in the page below. Congratulations, you've just created your first portlet!
Initial Setup
- Install Java Development Kit JDK 1.5 or higher, and set JAVA_HOME environment variable point to installation home directory of JDK, (Click here to know how to setup environment variable on different operating systems like windows / Unix / Linux platforms)
- For Windows, right click on My Computer -> Properties -> Advanced -> Environment Variables here you can add or edit windows environment variables e.g. if JDK is installed at "c:\program files\sun\jdk1.5" then set JAVA_HOME to "c:\program files\sun\jdk1.5"
- For Unix or Linux platforms go to home directory of user and add entry to set variable and export it in hidden file named .profile
For example,
JAVA_HOME=/usr/lib/java/java-1.5 export JAVA_HOME
- Add JAVA_HOME/bin directory to PATH environment variable. i.e. for windows set value of PATH to %JAVA_HOME%\bin;%PATH% and for Unix and Linux platforms set its value to $JAVA_HOME/bin:$PATH
export PATH=$JAVA_HOME/bin:$PATH
- Install ANT 1.7 or higher and set ANT_HOME environment variable value to ANT installation directory.
- Install Liferay portal with you choice of Application server (Click here for guideline to setup liferay portal and different platforms and application servers)
- Install Liferay Plugin SDK (Visit here to know guideline to install Liferay plugins SDK)
Creating portlets with the Plugins SDK is extremely simple. There is a portlets folder inside of the Plugins SDK folder. This is where your portlet projects will reside. To create a new portlet, first decide what its name is going to be. You need both a project name (without spaces) and a display name (which can have spaces).
When you have decided on your portlet's name, you are ready to create the project. For the greeting portlet, the project name is “hello-word”, and the portlet title is “Hello World”. Navigate to the portlets directory in the terminal and enter the following command
For Linux, Unix and Mac OS X:
./create.sh hello-word "Hello World"
For all windows platforms:
create.bat hello-word "Hello World"
You should get a BUILD SUCCESSFUL message from Ant, and there will now be a new folder inside of the portlets folder in your Plugins SDK. This folder is your new portlet project. This is where you will be implementing your own functionality. Notice that the Plugins SDK automatically appends “-portlet” to the project name when creating this folder. In this case you can find directory "hello-word-portlet" in side portlets directory
Deploying the portlet on Liferay Portal
- Make sure your Liferay Portal is already running or else you can start it by starting containing application server.
- To deploy open a terminal window in your portlets/hello-world-portlet directory and enter this command
ant deploy
You should get a BUILD SUCCESSFUL message, which means that your portlet is now being deployed.
If you switch to the terminal window running Liferay, and wait for a few seconds, you should see the message “1 portlet for my-greeting-portlet is available for use.” If not, something is wrong and you should double check your configuration.
Select the Sample category, and then click Add next to Hello World. Your portlet should appear in the page below. Congratulations, you've just created your first portlet!