Friday, April 25, 2014

Generic Portlet Development using Liferay Plugins SDK and ANT Tool

Liferay have given Plugins SDK to develop portlets and deploy into liferay portal environment.
Liferay Plugins SDK have used ANT tool to build and deploy the portlet applications.
So we need to install ANT tool in our machines.

Download Generic Portlet Examples


Before start all Java/JDK should be installed in our machine

Required Steps:

Step: 1

Install ANT so that we can build and deploy the portlet applications using Plugins SDK.

Download ANT binary distribution from Apache site

Extract in any desired directory.

Crete ANT_HOME system environment variable.

Add ANT bin path  i.e. %ANT_HOME%/bin to system path variable so that we can run ant commands from any directory.

Install ANT

Step: 2

Download Liferay Portal Server and configure data base properties in file which we need to place Liferay Home Directory.

Go through Following Link

Step: 3

Download Liferay Plugins SDK and Extract in desired Directory and change properties in build.prpoperties file and configure the portal server information. Provide Liferay Portal server information in Plugins SDK file

Instead of we change the properties in file we just clone the file and we modified it name as

Any property of needs to change then we will use file.

Example: (my system user name E5410)

The following is liferay portal server information in

app.server.portal.dir=D\:\\Liferay Work Space\\bundles\\tomcat-7.0.40\\webapps\\ROOT\:\\Liferay Work Space\\bundles\\tomcat-7.0.40\\lib\\ext
app.server.deploy.dir=D\:\\Liferay Work Space\\bundles\\tomcat-7.0.40\\webapps
app.server.dir=D\:\\Liferay Work Space\\bundles\\tomcat-7.0.40

Follow the articles for more information

Step: 4

Now open command prompt and go to Liferay Plugins SDK portlet directory (D:\Liferay Work Space\liferay-plugins-sdk-6.2.0\portlets)

Portlet create command as Follows

Create Command Syntax

create  PortletName  "portlet Display Name"  PortletFrameWork

Real Use In Command Prompt

create  hello-world "Hello World" mvc

We have different Portlet Frame work that supported By Liferay Plugins SDK



In the above we might not see generic portlet but first use mvc portlet after create the portlet Skelton then change portlet extended class with Generic Portlet and use the code which I explained in previous article.


To see portlet create command then open create.bat/ files in Plugins SDK portlets directory. Open create.bat and see the syntax and option for create command

Example path

D:\Liferay Work Space\liferay-plugins-sdk-6.2.0\portlets\ create.bat

Important Observations:
  • When we run portlet create command from Plugins SDK portlets Directory then it will create portlet application with basic configuration file and its application structure. we can say portlet project Skelton with basic artifacts.
  • Now we need to add more code and other pages then we need to deploy portlet

Portlet Application Skelton after we run the portlet create command

Inside WEB-INF (before run ant deploy target)

Portlet Deployment

As soon as we run portlet create command from Plugins SDK portlet directory then it will create the portlet application with basic configuration file and it application structure.

In the portlet project parent directory we can see build.xml file and it have some ant targets to compile and deploy the portlet.

Run following command from portlet project directory where build.xml file

ant deploy


To see available ant targets for portlet run following ant command

ant –p

 Once we run ant deploy target from portlet application then portlet will be deployed into liferay portlet server.

We already specify the portal server information in Plugins SDK build.proerties file so that as soon as we run ant deploy target portlet automatically deployed into server.

The following is screen show run portlet ant deploy target

Important Observation after run ant deploy target
  • Portlet ant deploy command is default ant target for portlet it’s responsible to deploy portlet into liferay portal environment and server information already provided in build properties file.
  • When we run ant deploy its will compile and package portlet application as war file and it will be deployed into portal server.
  • When we run ant deploy following action was takes place


All java classes and jsp pages will be compiled and at time of compilation it will create classes and lib directories in portlet WEB-INF directory.

All java .class file will be places in classes and if ant jar file then it will be places in lib 
directory. We can also add our project required jar file in lib directory.


In the packaging action all application files will be packages as war file and it will be placed in Plugins SDK /dist directory.


In the deployment action the created war file in dist directory will be copied into liferay portal server deploy directory.

As soon as war file places in liferay portal deploy directory then it will be copied into server deployment directory. Server deployment directory will be depends on server type


Tomcat Deployment Directory as Follows


Jboss Deployment directory as Follows:



Server deployment directory information we already provided in build properties file that is why war file will be copied specified server deployment directory.

At the time of deployment liferay will add some other additional configuration file and its configuration to portlet so that it will be run in the server successfully.


It will liferay-plugin-package.xml file
In Jboss environment it will add one more action files called jboss-deployment-structure.xml


The important thing here liferay will add more configuration and more files to the portlet to successfully run in different portal environments and it will be take care by hot deployment process.

Portlet Hot Deployment is mechanism and it responsible to deploy portlet successfully into different server’s environments to do this task it will add additional configurations and additional configuration files to portlet application.

That’s is what as soon as war file available in liferay deploy directory then it will be copied and unpacked in server deployment directory.

Best observation you can see as follows

See the web.xml file configuration in Portlet Application and some have look in deployed portlet application web.xml



D:\Liferay Work Space\bundles\tomcat-7.0.40\webapps\hello-world-portlet\WEB-INF\web.xml

Configuration files and Directories in Portlet Application before Deploy as follows

Configuration files and Directories in Portlet Application after Deploy as follows


As we already know portlet create command will be created Liferay MVC portlet and it will be extended MVCPortlet class but we want develop Generic Portlet

Modification required making it as Generic Portlet.

We already get the portlet Skelton with all configuration files and directories.

Step: 1

Change the portlet class in portlet.xml file to our custom class and that should extends the Generic Portlet Class

The following is configuration in portlet.xml file

<?xml version="1.0"?>
<portlet-app xmlns=""
xsi:schemaLocation="" version="2.0">
              <display-name>Hello World</display-name>
                     <title>Hello World</title>
                     <short-title>Hello World</short-title>
                     <keywords>Hello World</keywords>


Apart from portlet.xml file we have liferay-portlet.xml file and liferay-display.xml file you can see the tags inside those two file then you can understand more.

All liferay Configuration XML files DTD available in following location

Step: 2

Create src directory in portlet docroot/WEB-INF directory

Step: 3

Create java class in src directory that is we specifies in portlet.xml file in the previous step and java class should extends Generic Portlet class

Crete java class in the following package structure


The following is Portlet Class

public class HelloWorld extends GenericPortlet {

    public void init() {
        viewJSP = getInitParameter("view-template");
    public void doView(
            RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {
       String currentViewPage=renderRequest.getParameter("jspPage");
              include(currentViewPage, renderRequest, renderResponse);
              include(viewJSP, renderRequest, renderResponse);
    protected void include(
            String path, RenderRequest renderRequest,
            RenderResponse renderResponse)
        throws IOException, PortletException {

        PortletRequestDispatcher portletRequestDispatcher =

        if (portletRequestDispatcher == null) {
            _log.error(path + " is not a valid include");
        else {
            portletRequestDispatcher.include(renderRequest, renderResponse);

    protected String viewJSP;

    private static Log _log = LogFactoryUtil.getLog(HelloWorld.class);


Step: 4

Now run ant deploy target form portlet application directory then portlet will be deployed.
When deploy portlet if any compile errors will be display in command prompt console and build will be failed.

We already done many Generic Portlet Examples in Previous article you can apply all code sample and deploy portlet.


Before deploy the portlet make sure you portal server should be in running mode.

Using Portlet:

Access Liferay portal using you host name port

Generally when create portlet then it will be available in sample category.

Login as liferay admin in liferay portal in the application section you can see the sample category.

The following is login screen

Add portlet to page

Portlet Application Directory Structure Changes After Deployment

When we create portlet from create command then it will create portlet application in Plugins SDK portlets directory.

The portlet application Directory Name that is we provides in create command and its portlet root directory.

In Portlet Application we can see docroot directory and buil.xml file
build.xml file is ant file to deploy or build the portlet application i.e. deploy into liferay portal server.

docroot is directory there all portlet artifacts like jsp page and other directories will be available.

We can say portlet directory starts with docroot directory and for the development convenience liferay have made like that.

When we give the path names we will exclude the docroot directory in the name we specifies in the code or program.

At time of war package docroot will be excluded in portlet war file

Actual Portlet Application Structure

After Packages as War file or Deployed in Server Deployment Directory

When we observe above two screens in the second one docroon directory is not available it was excluded after packaged as war.


Ant+Plugins SDK not much flexible environment so that we will use Liferay IDE or MAVEN or Liferay Developers Studio for portlet development. But we need to have more undestand about all environments that is why this article help us.


Post a Comment

Recent Posts

Recent Posts Widget

Popular Posts