Showing posts with label Liferay. Show all posts
Showing posts with label Liferay. Show all posts

Monday, September 30, 2013

Liferay + Sonar + JMeter Configuration



Introduction:

This blog provides some useful information about the importance of the effects of coding style and practices on performance, maintainability and scalability on the software products. There is often elaborate discussions or debates over the “Effective” coding v/s “Efficient” coding.

“Efficient” often means code that is correct from the point of view of adhering to standards, using a widely accepted patterns/approaches for structures, regardless of project size, budget etc. “Effective” coding is not being “right”, but about getting things done. This often results in code that falls outside the bounds of commonly accepted “correct” standards, usage etc.

Developers often refuse to compromise their favored approach for the other. In my own experience I have found that people having formal education in software development tend towards efficient camp. Those who picked up software development more or less as a tool to get things done tend towards Effective Camp. When managing team of developers where not all are in one camp things become really challenging.

From this post I try how one can do self-improvement or help other team members improvise their code quality. Usually developers considers that the code completed by them is perfect but when this code gets integrated with the whole application may create issues. So, one has to do manual code review to understand the code and try to check if there is any issue with code affecting performance or scalability of application.

Manual Code review takes lot of time and effort and in this age of budget driven projects it becomes difficult to invest so much in manual code review.

If we can automate this process where code is continuously monitored to check against performance and scalability then things becomes easy to manage and monitor.

So I am going to provide details about how one can easily integrate Liferay with Sonar and Jmeter to help developers improvise their code and be a part of “Efficient” Camp.

 Pre-requisites:
Before we start with the tutorial make sure that your system is ready with the following:

1.       Java 1.5 or later
2.       Apache Ant (Download latest from here.)
3.       Liferay Portal Server (Download link.)
4.       Liferay Plugins SDK (Download link.)
5.       Sonar Server(Download Latest from here.)
6.       Apache JMeter (Download latest release from here.)
Download the latest version of the tools mentioned above in a folder named “Downloads”.

Tools Installation:

In this section we will learn the installation process of tools mentioned above:

Installing Liferay SDK:
Assumption: For this article I am going to work on Tomcat bundled Liferay 6.1.20.


  1.    After you have downloaded the tomcat bundled Liferay unzip the file which will create a folder named “liferay-portal-6.1.1-ce-ga2-ja”, rename this folder to “server” 
  2.  Once you have downloaded the Liferay plugins SDK from the link provided. Before you download the SDK check the version of Liferay you are working on and download the respective SDK. 
  3.    After downloading the SDK Zip file unzip the file into a folder called “plugins”.
  4. Open the plugins folder and make a copy of build.properties file under plugins folder and rename it to build.COMPUTER_NAME.properties.
  5. Keep the following properties and delete all the others:
# Specify the paths to an unzipped Tomcat bundle.
    #
    app.server.type=tomcat
    app.server.dir=${project.dir}/../bundles/tomcat-7.0.23
    app.server.deploy.dir=${app.server.dir}/webapps
    app.server.lib.global.dir=${app.server.dir}/lib/ext
    app.server.portal.dir=${app.server.dir}/webapps/ROOT
6. Change the property “app.server.dir” to PATH_TO_TOMCAT folder. for example if your server is installed under C Drive then the property will change to:

app.server.dir=C:/server/tomcat-7.0.23

7.       Do not change any other properties if you are using default setup of Liferay.


Installation of Apache ANT:
  1.  Once you have downloaded the apache ant zip file. Unzip the file and rename the folder to “apache-ant”.
  2. After unzipping the package we need to set the path for Ant. Open Control Panel and then open Advanced System Settings.
  3.  Click on the “Environment Variable” , Under System Variables click on “New…” button.
  4. Provide the variable name as “ANT_HOME” and provide the path of apache ant installation path. For example if you have unzipped the Ant zip file under Program Files(x86) then you path should be like “C:\Program Files (x86)\apache-ant-1.8.0\”.
  5. After setting ant home, we need to set path for the apache ant. Open the system variable with name “Path” in the edit mode and add the following path “C:\Program Files (x86)\apache-ant-1.8.0\bin\” and save the settings.
  6. Verify installation: to verify whether ant installation was a success open command prompt and type “ant --version” command if you see the version number in the next line then it means installation was successful.

Installation if Apache JMeter:
  1.  Once you have downloaded the Apache JMeter, unzip and rename the folder as “apache-jmeter”.
  2.  Open the Control Panel and open Advance System Settings , click on “Environment Variables” button.
  3. Under system variable click on “New…” button. Provide Variable name as “JMETER_HOME” and provide the path of apache JMeter installation path. For example if you have unzipped the JMeter zip file under Program Files(x86) then you path should be like “C:\Program Files (x86)\apache-jmeter\”.
  4. After setting jmeter  home, we need to set path for the apache jmeter. Open the system variable with name “Path” in the edit mode and add the following path “C:\Program Files (x86)\apache-jmeter\bin\” and save the settings.
  5. Verify installation: to verify whether jmeter installation was a success open command prompt and type “jmeter --version” command if you see the version number in the next line then it means installation was successful.

Installation of SONAR server:
  1. After downloading the latest version of Sonar from the link provided, unzip the file and rename the folder to “sonar”.
  2. Create a database called “sonar” in the mysql database.
  3. Under the sonar directory open the conf folder and then open sonar.properties file. sonar.jdbc.username: rootsonar.jdbc.password: root
  4. Uncomment the following line by removing ‘#’ symbol for configuring the Sonar with MySql database sonar.jdbc.url: jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 sonar.jdbc.driverClassName: com.mysql.jdbc.Driver
  5. Start the sonar server by running the file “\bin\windows-x86-32\StartSonar.bat”
  6. Once the server starts up with no errors you will see the following log :                                    "Started SelectChannelConnector@0.0.0.0:9000” 
  7. Open the browser and hit the URL : http://localhost:9000/
  8. Login using the following default credentials:                                                                                    username: admin                                                                                                                   password: admin
  9. If you are able to login then it means that you have completed the setup of Sonar successfully.

Configuring Liferay with Sonar:
  1. Download the sonar ant task jar file from this link and place it inside lib folder of directory.
  2. Open build.xml file under the “plugins” directory and add the following code:
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">



</taskdef>

<!-- Add the target -->

<target name="sonar">

<property name="sonar.jdbc.url" value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" />

<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" />

<!-- the username and password of your database -->

<property name="sonar.jdbc.username" value="root" />

<property name="sonar.jdbc.password" value="root" />

<!-- list of mandatories Sonar properties -->

<property name="sonar.sources" value="<relative-path-to-src-folders> " />

<property name="sonar.projectName" value="<project-name> " />

<property name="sonar.binaries" value="<relative-path-to-classes>" />

<property name="sonar.libraries" value="<relative-path-to-lib>" />

<sonar:sonar key="<project-name>" version="0.1-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant"/>

</target>



3.       Build the hooks/portlets using ant command using either “ant deploy” command or “ant compile” command. 
4.       Once the build for portlets is successful run ant task “ant sonar” to generate sonar reports. Make sure sonar task doesn’t throw any errors. 
5.       Login to the Sonar server to see the results.
6.       If you face any heap size while running sonar task use the following command:

for windows: set ANT_OPTS=-Xmx1g
for linux : export ANT_OPTS=-Xmx1g

Configuring Sonar with Jmeter:

  1.  Before you configure Sonar with JMeter you need to configure JMeter with Liferay. Please follow this link and once you have completed a test case with Liferay export the result as .jtl file.
  2. To configure JMeter with Sonar download the JMeter Reporting Server from this link.
  3. Once you have downloaded unzip the file and add configuration related to project as the following: testconfig.project_name.desc=project_name        testconfig.project_name.prject=PATH_TO_JTL_FIL  
  4. Here "testconfig.project_name.desc" is the name of Project. and "testconfig.project_name.jtlpath" is the path of Jmeter report file.
  5. Once you are done with changes in jmeter-report-server.properties file, then start Jmeter Report server by running jmeter-report-server.bat on Windows platform.\
  6.  Select Project in which you want to show output of Jmeter Load test result. Go to project Settings -> Jmeter.
  7.  Add below configuration and click on "Save Jmeter Settings" button:                                        Remote config name=project_name                                                                                         Remote server host=                                                     Remote server port=5555
  8. Now when next build will run, Sonar-Jmeter will show out of Jmeter Result file.

Tuesday, January 8, 2013

Working with Liferay EXT Plugin

Since Liferay 6.0 extension environment was moved to plugins, it transformed the way core functionalities can be overridden, but there are some best practices which justifies why ext development was moved to plugins.

The major reason why ext was moved to plugins was that in earlier versions of Liferay code had to be placed on the server to deploy ext, which was a major concern from potential customers. So if the customer uses Liferay 6.x version then best practice is NEVER keep source code on servers.

So one should use SSH for Linux servers or RDC for Windows Server to deploy the war files on the server.

As we all know that ext-plugin is still not 100% hot deployable and just because of this reason developers tend to use ant direct-deploy command to deploy ext on the servers. One more reason this command is used more frequently is that people find un-deploying ext-plugin difficult.

So following are some steps which will help in un-deploying the ext-plugin from the server:
Assuming the name of ext-plugin is "sample-ext"

1. Shut down server
2. Delete the folder sample-ext from "webapps" folder
3. Navigate to /webapps/ROOT/WEB-INF folder and delete the following files only:
a. liferay-display-ext.xml
b. liferay-portlet-ext.xml
c. portlet-ext.xml
d. tiles-defs.xml
e. ext-sample-ext.xml
4. Navigate to following location to delete only those jar files mentioned below:
a. ext-sample-ext-impl.jar
b. ext-sample-ext-util-bridges.jar
c. ext-sample-ext-util-java.jar
d. ext-sample-ext-util-taglib.jar
5. Navigate to following location to delete only the ext-sample-ext-service.jar file
6. Restart the server

By following the steps mentioned the ext changes are reverted back to original state once the server restarts and new version of ext can be re-deployed.

Note:
1. Avoid creating multiple ext-plugin in the same project to facilitate code manageability.
2. Using EXT Plugin should be avoided till its utmost necessary to modify any core features of Liferay.

Liferay Development Best Practices

Liferay Development Best Practices
Introduction:
Liferay portal is a portal framework which is an open source platform which can be customized to any level to deliver cross platform solutions. Liferay development has always been a point for discussion as Liferay provides different ways to customize Liferay or add new functionalities into Liferay.
Liferay Development offers following various ways to customize default behaviour of Liferay:
i. Portlets
ii. Themes
iii. Layout Templates
iv. Webs
v. Hooks
In order to use the various ways mentioned above one must follow the best practices to help in organizing and managing the code as well as defining the deployment strategies

This document will provide information about such practices and how to apply these practices.

1. Liferay Installation
Liferay installation involves three zip files such as liferay-portal-tomcat-6.1.0.zip, liferay-plugins-sdk.zip and liferay-portal-src.zip.
One needs to unzip these files and follow the regular installation steps to install Liferay.
2. portal-ext.properties
The file portal-ext.properties is the most important file in the whole Liferay development lifecycle as it holds to various configurations which are utilized within the portal or portlets. Once Liferay 6 was released ext became part of plugins-sdk and keeping portal-ext.properties file within ext is not a good practice.

Best Practice:
Placing the portal-ext.properties file at Liferay tomcat installation root folder is the best practice. For example : If Liferay Tomcat server is installed under the location : D:\\liferay-portal-6.1.0-ee-ga1 then placing the properties file under this location is the best practice.

Also, this file needs to be part of source repository and needs to be updated regularly. Another practice is to avoid using portlet.properties for custom portlets. So if there is need to use properties specific to portlets adding them to portal-ext.properties file is better.

3. Ext Plugin :
Since Liferay 6.0 extension environment was moved to plugins, it transformed the way core functionalities can be overridden, but there are some best practices which justifies why ext development was moved to plugins.

The major reason why ext was moved to plugins was that in earlier versions of Liferay code had to be placed on the server to deploy ext, which was a major concern from potential customers. So if the customer uses Liferay 6.x version then best practice is NEVER keep source code on servers.

So one should use SSH for Linux servers or RDC for Windows Server to deploy the war files on the server.

As we all know that ext-plugin is still not 100% hot deployable and just because of this reason developers tend to use ant direct-deploy command to deploy ext on the servers. One more reason this command is used more frequently is that people find un-deploying ext-plugin difficult.

So following are some steps which will help in un-deploying the ext-plugin from the server:
Assuming the name of ext-plugin is "sample-ext"

1. Shut down server
2. Delete the folder sample-ext from "webapps" folder
3. Navigate to /webapps/ROOT/WEB-INF folder and delete the following files only:
a. liferay-display-ext.xml
b. liferay-portlet-ext.xml
c. portlet-ext.xml
d. tiles-defs.xml
e. ext-sample-ext.xml
4. Navigate to following location to delete only those jar files mentioned below:
a. ext-sample-ext-impl.jar
b. ext-sample-ext-util-bridges.jar
c. ext-sample-ext-util-java.jar
d. ext-sample-ext-util-taglib.jar
5. Navigate to following location to delete only the ext-sample-ext-service.jar file
6. Restart the server

By following the steps mentioned the ext changes are reverted back to original state once the server restarts and new version of ext can be re-deployed.

Note:
1. Avoid creating multiple ext-plugin in the same project to facilitate code manageability.
2. Using EXT Plugin should be avoided till its utmost necessary to modify any core features of Liferay.

3. Hooks Plugin:
Hooks Plugin are the most powerful plugins as compared to any other plugins available within Liferay. One should be careful while using hooks plugin to modify presentation or functionalities of Liferay. Following are some of the best practices to be kept in mind while using hooks plugin:

1. Naming Convention:
Always provide proper naming conventions to hooks plugins. For example, If there is a need to create a hooks plugin for asset publisher then name that plugin as "asset-publisher-hook". This will notify other developers that this particular hook is for asset publisher.

2. Avoid Duplication
Some times developers will create hooks for same portlets more than once which results into conflict and confusion. This can be avoided if Naming convention is followed properly.

4. Portlets Plugin:
These plugin provide freedom to developers to create custom applications which are not part of Liferay OOB features. There are some best practices for such plugins as well which are mentioned as follows:
1. Naming Convention :
Providing proper names based on feature/functionality to the plugin portlets help in identifying the portlets. For example, If one create a portlet providing weather features can be named as weather-portlet.

2. Categorization:
Specifying the categories for the plugin portlets helps in grouping them based on functionality or project. If we consider the above weather-portlet as an example which was developed for customer ABC then mention the portlet categorization in liferay-display.xml as follows:





3. Service Builder
Service Builder tool is used to provide database connectivity to the plugin portlets so that portlet specific information can be persisted in the configured Database. While creating the plugin portlets always consider the bigger picture, like whether this portlet is a standalone portlet or there is a need to share the services of this portlet with another one.

In such scenarios developers will place the service jars in lib/ext folder to make the services global which can be consumed across any portlet. This creates chances of frequent restart of the portal if the service jar gets updated frequently.

The above situation can be avoided if such portlets where services needs to shared are defined under single portlet.xml.

4. CSS/JS/Images
Liferay supports/provides developers to add portlet specific CSS, JS and Images to plugin portlets. One should use this only at the time of development in local machines. When the unit testing is completed whole of the portlet specific CSS, JS and Images should be merged with theme to avoid conflicts with other portlets or theme itself.

For example, if there are two portlets ABC and XYZ and both are using some jQuery plugins. So keeping Jquery Library files in both the portlets separately will end up in either conflicts or performance issue so such common files should be made part of the theme so that they can be accessed globally.

5. Classes Files:
In order to avoid discrepancy between the various components of Liferay, NEVER COMMIT CLASS files to Code Repository. That is the most dangerous activity for the whole project. This can be avoided by configuring classes folder as ignored for check-in.

6. JDK Version
Liferay Portal Server comes with built in JRE and is configured by default. So whenever you are starting the portal server always keep a check of the JRE_HOME Attribute in the command prompt/logs.
Selection of version of JDK entirely depends on the system requirements, though best practice is to configure the JRE_HOME/JAVA_HOME to the installed JDK on the local system. In order to change these settings open up the setenv.bat file (which can be found under bin directory) in a text editor and modify the path of JRE_HOME as follows:

JRE_HOME=%CATALINA_HOME%/jre1.6.0_20/win
to
JRE_HOME=PATH_TO_INSTALLED_JDK

These are some of the best practices which I have learned from my experiences in Liferay Development.

I will keep adding more such best practices to help people work with Liferay the right way.


Liferay Migration Process from 4.x to 6.x

Introduction:


I am considering JBoss bundled Liferay Portal.

Liferay is a portal framework which can be used to create and manage web portals in a much easier way than any other existing portal framework. Liferay has been evolving since they released Liferay 4.2.3 Portal with many user friendly features which soon started getting popular. Today the released version of Liferay is Liferay 6.1 with many more enhancements and new features which makes Liferay the most downloaded open source software of all times.

As Liferay was evolving there was need to support migration from an old version to any other version above this version. So Liferay came up with migration APIs to facilitate the migration process.

This document will describe approach and guidelines of how to understand and perform database migration from Liferay 4.2.3 to Liferay 6.1.

As per the recommendations from Liferay regarding database migration, we need to perform the migration in 3 stages stated below:

Stage I - Migration from Liferay 4.2.3 to Liferay 5.2.3
Stage II - Migration from Liferay 5.2.3 to Liferay 6.0
Stage III - Migration from Liferay 6.0 to Liferay 6.1

Prerequisites:

In order to initiate the migration following are the prerequisites:
1. Liferay 4.2.3 Database Dump
2. Liferay 5.2.3 portal bundled with JBoss
3. Liferay 6.0 portal bundled with JBoss
4. Liferay 6.1 portal bundled with JBoss
5. Access to SQL Query Browser, for example if DB is MySQL then we need MySQL Query Browser

Methodology:

Step I

Take the DB dump and import the dump to another database. For Example , if the database name of Liferay 4.2.3 is "ABC" then take a backup as ABC.sql. Create a database with name "XYZ" and import ABC.sql into this database.

This will create a copy of the LIVE database, this step is very important because doing migration on the Live DB directly is risky and not recommended.

Step II

Once you have the copy of the Database, next we need to set up a vanilla Liferay 5.2.3 bundled with JBoss on the local system. As we know we need to create portal-ext.properties file to configure Liferay with a database., so once the file is created we need to mention the database name of the one which needs to be migrated. In this case it will be XYZ.

Once you have provided the details to connect to the DB, simply start the server. Liferay portal will identify by itself that the database to which is connected right now is of old version and based on the version number respective Upgrade process will be initiated.




Step III

In the upgrade process based on the version schematic changes are initiated on the DB. This will involve temporary back up of tables, then creation of new table structure and inserting the data into the table.

Once the upgrade process is completed then Verification Process is initiated. This process actually verifies that the data which is present in the table is as per the requirements of Liferay 5.2.3.

Once the data gets migrated to desired version try logging into the server and cross check the data which got migrated with original database.

By following the steps mentioned above migration process can be carried out for the other two stages.

Points to Remember:

1. If using a windows machine where the migration will be carried out then start the server within the command prompt using "catalina.bat run" command. This will help you in checking the logs even if there is a System Exception which caused the server to shutdown.

2. During the migration process if any exception occurs resulting into system error leading to shutdown of server, then check from logs to which version Liferay was upgraded to. For example, if in the logs its mentioned that Upgrade successful to 5.0.01 version then execute the following query for "release_" table in the database.

"update XYZ.release_ set build =5001 where releaseId=1"

3. By executing this query we have updated build number of the database to the version its already upgraded. If we do not execute the query and start the server then server will start from 4.2.3 schema only. So by executing this we have saved sometime.

4. During the migration process there may be chances of elevated usage of JVM so make sure that the Perm Size, Heap size are defined properly to avoid any performance issues.

5. Also, If experiencing same problem during migration again and again at the same stage then do check the associated source files, Liferay has some issues in their upgrade process. You may end up coding in ext for making upgrade process proper.

6. Upgrade process never makes any changes to custom tables present within the Database, but if these tables are being used in conjunction with another out of box tables then there will be changes involved at each level.

7. Apart from all the above criteria there will still be issues which may come up during the migration. All such issues will be different from case to case.

Tuesday, February 23, 2010

Struts Portlet Using Netbeans in Liferay Plugin Environment

Well when i started with development of portlets using Netbeans IDE my greatest challenge was to create a struts portlet using portal pack for Liferay development. I knew what struts is but I didn't knew how liferay handles struts.

After getting to know how liferay handles struts, still my major concern was to create a Generic Struts Portlet.

So keeping these things as my goal I downloaded Netbeans 6.5 IDE and portal pack v 3.0.3_all and installed netbeans on my system. After installing I installed Liferay 5.2.3 version on my system, I configured this Liferay instance to mysql DB.

Well I don’t have much experience in Liferay but still could manage to complete this challenge.

I was also quite successful in importing ext environment and plugin environment into the netbeans for faster development of portlets. If anyone wants some info about it do post me your request I will surely help you out.

Anyways let’s come back to main point, so before starting off with this tutorial please check for the following prerequisites

  1. Netbeans IDE 6.5 or later
  2. Portal Pack for Netbeans IDE (latest build)
  3. Some basic knowledge of struts

One request is that please follow the instructions carefully if you skip then you will not get the exact output.

So let’s Start

STEP I

After starting IDE and adding all the plugins for portal pack into the netbeans, Click on New Project icon IDE and select category of project ad Web Project



After selecting category click on “Next”.

STEP II

Give a meaningful name to your project, like I have chosen as SampleStruts as shown below.




STEP III

In this step we need to select the server for development and deploying our portlet.

Here I choose the Liferay bundled tomcat server for the development.




After selecting the server click on “Next” to add Frameworks into the project.

STEP IV

For the development of portlets we will add Portlet Support to the project and struts support to help in creating struts portlet.




Once you have added the portlet and struts support into the project then click on “Finish”. IDE will by itself generate the following project dir structure.





Till this step IDE will help in creating the entire necessary configurations file.

STEP V

The first step is to delete the files index.jsp and welcomestruts.jsp for the project, after deleting the specified files then create these folders under the web pages folder.

  1. Css
  2. Html
  3. Js

  • Under css put portlet specific CSS file for example, sample.css.
  • Under html create more folders like portlet and then samplestruts folder inside portlet folder.
  • Use js folder for keeping JavaScript files which are portlet specific
At the end of the above your directory structure should be similar to the following pic:




STEP VI

Now let’s create portlet:

In order to create portlet right click on the project node and select the option New>Portlet



Once you select this option one window will open where you need to put some portlet information so according to your will enter the details. And your screen should look like the one below:



Once you have entered all the details for the portlet then click on “Next”. You will see one more screen where you need to check the option for “Create Jsps” (see screen below).




Now simply click on “Finish” so that IDE will create portlet specific files and you dir structure will look as shown below.








STEP VII


Now we will have to do a lot of manual stuff from now on so be careful and don’t miss out anything.

We need to create a lib folder under WEB-INF folder where you need to place one jar file by name portal-bridges.jar. In order to locate this jar files go to lib folder of your tomcat server under WEB-INF folder

We also need to add a compile time library struts.jar in order to do this follow the steps given below:

  • Right click on project node select “Properties”
  • Select Libraries option from left side menu
  • Click on Add Jars/Folder
  • Navigate to lib folder of server under WEB-INF folder and select struts.jar and click on open
  • After the above step click on “Ok”
  • By doing this we add struts.jar to the folder

As we need to have some files which all portlets should have like init.jsp and template.jsp so we create two JSPs under this path “/html/portlet/sample_struts”. Once these files are created then copy and paste the following code into respective files.


For init.jsp


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<%@ taglib uri="http://portals.apache.org/bridges/struts/tags-portlet-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="nested" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>

<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.ResourceBundle" %>

<%@ page import="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.ResourceURL"%>
<%@ page import="javax.portlet.WindowState" %>
<%@ page import="javax.portlet.PortletMode" %>
<%@ page import="javax.portlet.PortletConfig" %>
<%@ page import="javax.portlet.RenderRequest" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.PortletContext" %>
<%@ page import="javax.portlet.PortletRequest" %>
<%@ page import="javax.portlet.PortletSession" %>
<%@ page import="javax.portlet.PortletResponse" %>
<%@ page import="javax.portlet.PortletException" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="javax.portlet.ValidatorException" %>
<%@ page import="javax.portlet.UnavailableException" %>

<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>

For template.jsp


<%@ include file="init.jsp" %>
<tiles:useAttribute id="tilesPortletContent" name="portlet_content" classname="java.lang.String" ignore="true" />

<div>
<jsp:include page='<%= "/html/" + tilesPortletContent %>' flush="true" />
</div>



STEP VIII


Cut and paste SampleStruts.jsp from jsp folder under WEB-INF folder to this path “/html/portlet/sample_struts”.


STEP IX

Open web.xml and replace the code with the following code(remove br):



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextClass</param-name>
<param-value>com.liferay.portal.spring.context.PortletApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/META-INF/misc-spring.xml,WEB-INF/classes/META-INF/data-source-spring.xml,WEB-INF/classes/META-INF/base-spring.xml,WEB-INF/classes/META-INF/hibernate-spring.xml,WEB-INF/classes/META-INF/infrastructure-spring.xml,WEB-INF/classes/META-INF/portlet-spring.xml,WEB-INF/classes/META-INF/ext-spring.xml</param-value>
</context-param>
<listener>
<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
</listener>
<listener>
<listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>PortletActionServlet</servlet-name>
<servlet-class>com.liferay.util.bridges.struts.LiferayPortletServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>1</servlet-name>
<servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-class</param-name>
<param-value>org.apache.portals.bridges.struts.StrutsPortlet</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>PortletActionServlet</servlet-name>
<url-pattern>/portlet_action/*</url-pattern>
</servlet-mapping>
</web-app>




STEP X

Open portlet.xml file and replace the code with the following code and again change it according to your portlet details



<?xml version='1.0' encoding='UTF-8' ?>
<portlet-app xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
<portlet>
<description>SampleStruts</description>
<portlet-name> SampleStruts </portlet-name>
<display-name> SampleStruts </display-name>
<portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
<init-param>
<name>ServletContextProvider</name>
<value>com.liferay.util.bridges.struts.LiferayServletContextProviderWrapper</value>
</init-param>
<init-param>
<name>ViewPage</name>
<value>/portlet_action/sample_struts/view</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<resource-bundle>com.sample.struts.messages</resource-bundle>
<portlet-info>
<title> SampleStruts </title>
<short-title> SampleStruts </short-title>
<keywords> SampleStruts </keywords>
</portlet-info>
</portlet>
</portlet-app>


STEP XI

Open Liferay-portlet.xml replace the code with this code and again change according to your portlet details:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 4.4.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_4_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>Sample</portlet-name>
<portlet-url-class>com.liferay.portal.apache.bridges.struts.LiferayStrutsPortletURLImpl</portlet-url-class>
<instanceable>false</instanceable>
<header-portlet-css>/css/Sample.css</header-portlet-css>
<header-portlet-javascript>/js/jquery.validate.js</header-portlet-javascript>
</portlet>
<role-mapper>
<role-name>administrator</role-name>
<role-link>Administrator</role-link>
</role-mapper>
<role-mapper>
<role-name>guest</role-name>
<role-link>Guest</role-link>
</role-mapper>
<role-mapper>
<role-name>power-user</role-name>
<role-link>Power User</role-link>
</role-mapper>
<role-mapper>
<role-name>user</role-name>
<role-link>User</role-link>
</role-mapper>
</liferay-portlet-app>

STEP XII

Open struts-config.xml and put this code under action-mappings tags



<action path="/sample/view" forward="portlet.sample.view"></action>


STEP XIII

Open tiles-defs.xml and put these definitions as given below:



<tiles-definitions>

<definition name="portlet.sample" path="/html/portlet/sample/template.jsp"></definition>
<definition name="portlet.sample.view" extends="portlet.sample">
<put name="portlet_content" value="portlet/sample/Sample.jsp"></put>
</definition>
</tiles-definitions>



STEP XIV

After following these steps start the Liferay server see the below screen for reference :




STEP XV

Deploy the project by right clicking on the project node and click “Deploy”.

Once the build is successful go to http://localhost:8080/ and login as test and then add this application under User_portlets category.