Developing in the Liferay Lane

>> Monday, February 22, 2010

I have been studying the Liferay portal  system in the past few weeks and I must admit I am quite impressed with this JSR-168 implementation. I will have the chance to discuss this solution some other time but for now, I want to share some tips and tricks to setup an environment to develop Liferay "plugins".

In fact, setting up a development environment to work with Liferay can be quite challenging and time consuming. It is very easy to mess up and things can go wrong in many areas. Furthermore, the instructions are not always clear or complete and there a few tricks one can pull when working with Eclipse and Tomcat that will make things  more fluid. After a lot of suffering and trial and error, here is a recipe to setup a development environment with  Eclipse 3.5.x, MySQL, Liferay 5.2.3 and Apache Tomcat 6.0.x. I just hope I did not forget anything since after the fact, we sometimes miss out or omit a step. Let me know if corrections are needed. My system is running Ubuntu 9.1 but the recipe should be easy to adapt to a Windows box. So here we go.

  • Install (if needed) MySQL (I use MySQL 5.1.37).
  • Create a new MySQL database called "lportal" and test the connection parameters.
  • Install Eclipse 3.5 (Galileo) JEE Edition. You will need JEE edition for some of the tricks below.
  • Download and install Apache Tomcat 6.x somewhere and make sure it is setup properly and working (probably best to have a dedicated Tomcat installation).
  • Create a Tomcat server profile in Eclipse (JEE perspective/Servers view/Add server).
  • Download and unzip it in the folder of your choice ( you will end up with a liferay-portal-src-5.2.3 subfolder)
  • Import the contents of liferay-portal-src-5.2.3 as an Eclipse project (it already has the ".project "and ".classpath" files). A "portal" project should appear in your list of Eclipse project.
  • Create a "release.[USERNAME].properties" file in the root of the portal project where [USERNAME] is your Windows or Linux user name.
  • Add the following lines to the release.[USERNAME].properties file. Replace [ECLIPSE_PROJECTS_ROOT] and [ECLIPSE_WORKSPACE_ROOT] with the full paths for your setup The first folder is where you want to put the Liferay "ext" Eclipse project content.

  • Open an ANT view in Eclipse and drag the portal/build.xml file onto the view.
  • Launch (doubleclick) the "clean" task in the ANT view (should be optional the first time).
  • Launch the ANT "start" task followed by the ANT "build-ext" task.
  • Import the "ext" project into Eclipse (use "Import existing project" wizard). You should find it in [ECLIPSE_PROJECTS_ROOT]/liferay-ex.
  • In Eclipse, create a new file:  /ext/ext-impl/src/
  • Add the following lines to this file and make sure you set the proper paths and values for all the properties.


# Mail

  • Add the following file to the Eclipse "ext" project root: app.server.[username].properties. Make sure all the properties have the proper values.

  • In Eclipse, add the ext/build.xml file to your ANT view and launch the "deploy" task.
  • In Eclipse, configure a Tomcat server that refers to the Tomcat that you are using for Liferay and make sure it is configured to "Use Tomcat Installation". Also, change the timeouts to give enough time for Liferay to start (I specified 120 secs).
  • Start Tomcat from Eclipse. You should be getting a trace of Liferay starting up and if you look at your MySQL database, you should see the tables appear.
  • If everything goes well, the Liferay home page will automagically appear in your browser.
Creating and deploying a plugin

Now the interesting part for your portlet or theme development.
  • Download and install the Liferay portlet SDK (
  • Follow instruction to create a new portlet or theme.
  • For a theme, lets assume we created a new theme called "jazz-theme". Create a new static web project in Eclipse, name it "jazz-theme" and set the project contents to the [liferay_sdk]/themes/jazz-theme folder created with the SDK.
  • Add a file called "jazz-theme.xml" to root of the "mirasol-theme" Eclipse project and set its content as follows (replace [liferay_sdk] with the full path of the sdk):
  • Add the following task to the "build.xml" ANT file for the jazz-theme project ([resource.repositories.root]/deploy" is the folder used by liferay for hot deployment) :
[target name="redeploy"]
[copy file="[liferay_sdk]/themes/mirasol-theme/mirasol-theme.xml"
  • Using the ANT view, launch the "redeploy" task for the mirasol-theme project. You should see somehting like this in the Tomcat console:
19:40:40,987 INFO [ThemeHotDeployListener:90] Registering themes for mirasol-theme
19:40:41,020 INFO [ThemeHotDeployListener:114] 1 theme for mirasol-theme is available for use
  • From the Liferay web page, you should be able to access the new theme and is you change an image, CSS or other resource, simply launch the "redeploy" task and liferay will pickup the changes without having to copy all the files since the "docbase" attribute points to the Eclipse project folder.
  • The same idea applies to portlet projects.

Have fun and let me know if this works (or does not work) for you.

A good part of this "How-to" is based on information from this blog.

0 commentaires:

Post a Comment

  © Blogger template Webnolia by 2009

Back to TOP