Main Menu



You are here: Home
Liferay, Portlets and Maven PDF Print E-mail
Written by Josh B   
Wednesday, 09 February 2011 19:25

Tags: eclipse | java | maven | portlets

Dashboards seem to be the new Corporate buzzword. There's a dashboard for this and a dashboard for that. The current meme is that whatever the Web App, a dashboard will make it more friendly to end-users. No doubt they are very useful for showing a lot of information at one time. But they can be a pain to develop. That is where a Portal server comes in handy.

Liferay is a Portal server that integrates with Tomcat (as well as other Servlet Containers/App Servers). Its very similar to Joomla and Drupal, but has all the advantages that come with Java. Scalability, Reliability and allows developers to use all the API's and development tools that Java enjoys. (Depending on your view of Eclipse, though).

My interest in it is that it provides an easy way to get a Java-based Web App to completion, especially Dashboards... There's no more having to develop user management systems, no more having to develop a custom UI, or even spend time configuring your favourite Web Framework. (Struts 2, help...!)

Here's a quick tutorial on installing Liferay so that you can use Maven (and Eclipse) to help develop Portlets.

First download and install Liferay from the Liferay website. (Make sure you expand the drop-downs to see all the files.) Download and unzip both liferay-portal-src-6.0.5.zip and liferay-portal-tomcat-6.0.5.zip in a directory called liferay. Rename liferay-portal-6.0.5 to bundle. Make a directory called plugin-sdk liferay-plugins-sdk-6.0.5 and unzip liferay-plugins-sdk-6.0.5.zip in it.

From the bundle directory make sure you remove the sevencogs-hook and sevencogs-theme directories from the Tomcat Webapp directory. (If you leave them in they will install the demo content into the database : annoying...!)

Add a file called portal-ext.properties into webapps/ROOT/WEB-INF/classes:

## MySQL
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:3306/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=user
jdbc.default.password=secret

Create this database in Mysql.

You can now start Liferay. It will go away and install the needed tables and some demo data. Log in with the default user / pass of " This e-mail address is being protected from spambots. You need JavaScript enabled to view it /test". It's probably best to create your own user.

Go to the Liferay source folder, and add the following lines to build.properties

maven.version=6.0.5
maven.url=your repository url

The version number is the version of Liferay that you are using and this is added to the poms generated for all the Jars. (The Repository Url isn't important as there appeared to be a bug in the deploy section.) Be careful when running the make jars command as with me it seemed to destroy my Liferay install. Backup your current installation before doing so. (I think this happened when "clean" ran...)

ant clean start jar

Now store the Jars made in your local repository (ie, on your machine).

ant -f build-maven.xml install-artifacts

Now, go to the Plugins SDK and create a temporary Portlet with the script in liferay-plugins-sdk-6.0.5/portlets/. (You will have to give the scripts appropriate permissions to do this.)

./create.sh test

Now create Portlet Project outside of your normal Eclipse workspace. This will be the project we will be working on in Eclipse.

mvn archetype:generate

The Liferay Portlet Archtype is option 10.

Now find the temporary portlet you created with the "create.sh" script. Copy the tld directory in the WEB-INF directory to your new Maven based projects WEB-INF directory. Eg:

cd ~/bin/liferay/liferay-plugins-sdk-6.0.5/portlets/test-portlet/docroot/WEB-INF
cp -r tld ~/tmp/helloworld_portlet/src/main/webapp/WEB-INF/

Convert the project into an Eclipse project:

mvn eclipse:eclipse

Import the Project into Eclipse with the Existing Project Importer. Be sure to copy the Project into your workspace.

You will need to update the pom.xml file to point to the correct place to deploy files. Change the liferay.auto.deploy.dir property so it looks like:

<properties>
<liferay.auto.deploy.dir>/home/josh/bin/liferay/bundles/deploy</liferay.auto.deploy.dir>
<liferay.version>6.0.5</liferay.version>
</properties>

You can now code your Portlet in Eclipse. When you are ready to test your efforts, use the following to deploy the portlet in Liferay.

mvn -Dmaven.test.skip clean package
mvn liferay:deploy

Of course, we could just copy (cp) the war file from the target directory to Liferay, but this makes a much more stream-lined approach. It also means we can then start to integrate the war into other applications (ie, a Testing Suite such as Continuum or Hudson).

Happy Portleting...!

 

See also : Liferay and Ajax

 

Top Tip: To use the JSTL you will need to add both standard-1.1.2.jar and jstl-1.2.jar to the Liferay Tomcat Ext Lib directory.

Last Updated on Thursday, 17 February 2011 15:16
 

Comments  

 
+1 #1 Andres Vasquez 2011-02-16 21:13 Thank's Josh, this article was very useful for me to understand how to integrate maven with my liferay developments.

Huge from Chile.

Andrés
Quote
 
 
+1 #2 Juanjo Fuentes 2011-03-21 10:43 Thank you very much Josh, you helped me with this article. Quote
 
 
+1 #3 Andrea 2011-06-21 14:47 Thanks for the article Josh.
2 corrections:

1. Rename liferay-portal-6.0.5 to bundles

2. Go to the Liferay source folder, and add the following lines to build.your_username.properties
Quote
 
 
0 #4 Absaar 2011-07-08 10:53 Thanks buddy… it helped me going Quote
 
 
0 #5 Elaheh 2011-07-25 11:42 Thanks your guide was really helpful. Quote
 
 
0 #6 mcahornsirup 2011-08-23 16:00 There is an artifact for that. Maybe it is easier in some cases… what I'am really interested in is the testing strategies, you use for testing your portlets. Can you tell us about this? Quote
 

Add comment


Security code
Refresh

Joomla! Template by Red Evolution - Joomla Web Design