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 liferay-portal-src-5.2.3.zip 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.

    lp.ext.dir=[ECLIPSE_PROJECTS_ROOT]/liferay-ext
    lp.eclipse.dir=[ECLIPSE_WORKSPACE_ROOT]
    lp.eclipse.project.name=ext
  • 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/portal-ext.properties
  • Add the following lines to this file and make sure you set the proper paths and values for all the properties.
auto.deploy.dest.dir=${auto.deploy.tomcat.dest.dir}
auto.deploy.tomcat.conf.dir=[TOMCAT_HOME]/conf/Catalina/localhost

#
# 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=root
jdbc.default.password=

#
# Mail
#
mail.session.mail.pop3.host=opnworks.com
mail.session.mail.pop3.password=
mail.session.mail.pop3.port=110
mail.session.mail.pop3.user=lgauthier
mail.session.mail.smtp.auth=false
mail.session.mail.smtp.host=relais.videotron.ca
#mail.session.mail.smtp.password=
mail.session.mail.smtp.port=25

resource.repositories.root=[HOME]/liferay
  • Add the following file to the Eclipse "ext" project root: app.server.[username].properties. Make sure all the properties have the proper values.
app.server.type=tomcat

app.server.tomcat.version=6.0
app.server.tomcat.dir=[TOMCAT_HOME]
app.server.tomcat.bin.dir=${app.server.tomcat.dir}/bin
app.server.tomcat.classes.global.dir=${app.server.tomcat.dir}/lib
app.server.tomcat.classes.portal.dir=${app.server.tomcat.portal.dir}/WEB-INF/classes
app.server.tomcat.deploy.dir=${app.server.tomcat.dir}/webapps
app.server.tomcat.lib.endorsed.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.lib.global.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.lib.portal.dir=${app.server.tomcat.portal.dir}/WEB-INF/lib
app.server.tomcat.lib.support.dir=${app.server.tomcat.dir}/lib/ext
app.server.tomcat.portal.context=ROOT
app.server.tomcat.portal.dir=${app.server.tomcat.deploy.dir}/${app.server.tomcat.portal.context}
app.server.tomcat.log.dir=${app.server.tomcat.dir}/logs
app.server.tomcat.temp.dir=${app.server.tomcat.dir}/temp
app.server.tomcat.work.dir=${app.server.tomcat.dir}/work
app.server.tomcat.zip.name=liferay-portal-tomcat-6.0-${downloads.version}.zip
app.server.tomcat.zip.url=${sourceforge.mirror}/${app.server.tomcat.zip.name}
  • 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 (liferay-plugins-sdk-5.2.3.zip)
  • 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):
[context
antijarlocking="true">
antiResourceLocking="true"
path="jazz-theme"
docBase="[liferay_sdk]/themes/jazz-theme/docroot"
/]
  • 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"
todir="[resource.repositories.root]/deploy"/]
  • 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.

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

0 commentaires:

Post a Comment

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP