Subscribe Now!

Enter your email address:

Thursday, March 29, 2012

How Create Build and Deploy Liferay Portlets


A Liferay portlet is nothing but a web application consisting of Java classes, JSP, images, Javascript files. Here we will discuss the ways in which a Liferay portlet can be created.
There is an ANT script file which comes with the Liferay plugin SDK. This ANT script has various tasks for creating, building and deploying the portlet to Liferay server. All these ANT tasks can either be run using command line or by using Liferay 6 plugin for Eclipse. This Eclipse plugin also runs these ANT tasks behind the same. So its basically the ANT tasks that we want to run.


Creating Portlet:
The ANT command “create”, creates an empty portlet which is a web application having deployment descriptor web.xml inside the WEB-INF folder. There is also one JSP file named view.jsp being created which is the default first view of the portlet. In Liferay 6 plugin for Eclipse, we need to create a new Liferay Plugin project which also results in the creation of above described web application structure.
Meeting Functional Requirements:
To meet the functional requirements, one can write the view code in JSP. The database interaction code (business logic) can be written inside Java classes. This Java code can be either invoked using JSP scriptlets or JSP taglibs depending upon the size and requirements of the portlets. The DAO and DTO can be generated by using the service builder. The service builder reads service.xml and generates the Java classes for database CRUD operations.
The ANT task names “build-service” is responsible for generating the DAO and DTO code. With Liferay 6 plugin for Eclipse, there is a build service button displayed when service.xml is opened.
The service builder creates a JAR file of the generated code and places the same on CLASSPATH (inside lib folder of the portlet). After generating the DAO and DTO code, one can use them to write the business logic which includes the code required for interaction with database.
One more point worth mentioning is that the service builder only generates Java code and does not create the database tables corresponding to the entities mentioned in the service.xml. The database tables are created by the Liferay server after service builder has been run and portlet has been deployed. This means that the service builder creates entry somewhere inside the Liferay server so that the database tables can be created.
Deploying the Portlet:

The portlet is created and built inside the plugin SDK of Liferay. After writing the view code and business logic, it has to be deployed on to the Liferay server. The deployment is in the form of packaged WAR file. There is again one ANT task named “deploy” which compiles all the Java code and generates the WAR file which is then copied to Liferay server’s deployment folder (the folder named “deploy” present outside Tomcat, JBOSS etc.). The deploy ANT task can also be invoked from Liferay 6 plugin for Eclipse using the “Run on Server” feature of Eclipse.
Liferay server comes with Hot deployment feature which means that once the ANT task for deployment has run, the server detects the change and automatically loads the Liferay portlet application so as to make it available for use.
In this process of deploying the portlet, any required database changes are made by the Liferay server.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...