« Back to Development...

Development Environment (Ubuntu Linux)

This article is dated and needs updating.

Setting Up The Liferay Development Environment on Ubuntu Linux #

This guide will aid in the set-up of the Liferay development environment on Ubuntu linux. It assumes that you have a basic installation of Ubuntu linux on your machine. For this guide, Ubuntu 6.10 (Edgy) will be used as well as Liferay v4.2 .

For the purpose of demonstration, Eclipse will be the IDE used to set up the development workspace and debugger. Workspaces for Liferay trunk and an Ext environment will be created.

Install Required Tools #

The first step in setting up the development environment is installing the required tools. For the purposes of this guide, we will be using APT (Advanced Packaging Tool) in order to download, install, and configure our tools. Please make sure you have the proper repositories (in this case for Ubuntu Edgy) for APT before you start using this tool.

We will use the sudo command throughout this guide, but you may login as root and omit the sudo portions of the commands if you prefer. Commands to type are in dashed boxes. File contents are displayed in a similar fashion.

Java Development Kit (JDK) v5 #

    sudo apt-get install sun-java5-jdk
  • Accept the licence agreement that appears.
  • Set Sun's JVM as default Java version:
    sudo update-java-alternatives -s java-1.5.0-sun
  • Edit /etc/jvm and move /usr/lib/jvm/java-1.5.0-sun to the top of JVMs offered:
    gksudo gedit /etc/jvm

reference: [http://ubuntuguide.org/wiki/Ubuntu Edgy#How to install Java Development Kit .28JDK.29 v5.0

You|will need to set JAVA_HOME in order for Tomcat to startup correctly. You can set this in your .bashrc file in your /home/<username>

    #Java
    export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun-1.5.0.08

Check Java version

    java -version

You need to set this for the Eclipse settings files as well in order for Eclipse to use the proper JVM. We will go into more detail in the Eclipse set-up portion of this guide.

Java Development Kit (JDK) v6 #

You may need or want to install JDK version 6 depending on your requirements. If so, here is how:

    sudo apt-get install sun-java6-jdk
  • Accept the licence agreement that appears.
  • Set Sun's JVM as default Java version:
    sudo update-java-alternatives -s java-6-sun
  • Edit /etc/jvm and move /usr/lib/jvm/java-6-sun to the top of JVMs offered:
    gksudo gedit /etc/jvm

You will need to set JAVA_HOME in order for Tomcat to startup correctly. You can set this in your .bashrc file in your /home/<username>

    #Java
    export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.00

Check Java version

    java -version

You need to set this for the Eclipse settings files as well in order for Eclipse to use the proper JVM. We will go into more detail in the Eclipse set-up portion of this guide.

Ant #

    sudo apt-get install ant

Jikes #

You don't need this unless you have issues using ECJ (setup a little later) (I suggest trying to setup ECJ before using jikes.)

    sudo apt-get install jikes

SVN #

    sudo apt-get install subversion

There will be extra steps on how to use SVN to create and update from the code repository [http://wiki.liferay.com/index.php/Liferay_Development_Environment:_Ubuntu_Linux#Liferay_trunk further down the guide]].

**MySQL** (6.10 Edgy) #

    sudo apt-get install mysql-server
  • MySQL comes with no root password as default. This is a huge security risk. You'll need to set one. So that the local computer gets root access as well, you'll need to set a password for that too. The local-machine-name is the name of the computer you're working on (i.e. - localhost). For more information see here .
    mysqladmin -u root password your-new-password
    mysqladmin -h local-machine-name -u root -p password your-new-password
    sudo /etc/init.d/mysql restart
  • Create the Liferay database. At the linux prompt:
    mysql -u root -p <<< "create database lportal;"
  • Download script create-mysql.sql from Liferay Portal SQL Scripts here .
  • Navigate to where the script is located. It is in the "create" directory. You may want to edit the script to change the name of the database, but only if you prefer.
  • In command prompt, run mysql script by entering:
    mysql -u root -p < create-mysql.sql

Reference: [http://ubuntuguide.org/wiki/Ubuntu Edgy#How to install MYSQL Database Server|http://content.liferay.com/4.0.0/docs/install/ch01s05.html]

**MySQL** (7.10 Gutsy) #

    sudo apt-get install mysql-server
  • MySQL's root password is set in an interactive prompt during installation.
  • It's highly suggested that a separate database user account be created to handle all things portal related.
    mysql -u root -p <<< "create user 'portal'@'localhost' identified by 'portal'; grant all on lportal.* to 'portal'@'localhost';"
  • Download script create-mysql.sql from Liferay Portal SQL Scripts here .
  • In command prompt, run mysql script by entering:
    mysql -u portal -p < create-mysql.sql

Liferay-Tomcat bundle #

The Liferay-Tomacat bundle is simply Liferay preconfigured and deployed onto Tomcat. You can find it here:

http://www.liferay.com/web/guest/downloads

Download Liferay Portal Professional 4.2.0 (Bundled with Tomcat for JDK 5.0)

Unzip the bundle into a directory like /work/projects/liferay/tomcat

To test that your Tomcat runs correctly, at the command prompt:

    cd /work/projects/liferay/tomcat/bin
    . startup.sh &

If you get an error regarding catalina.sh then you might have to set executable permissions on the .sh files in tomcat/bin. As well, check that $TOMCAT_HOME is set, by trying "echo $TOMCAT_HOME"

In linux, the startup script will not automatically display a tomcat console. To do this, open a new terminal window and type:

    tail -f $TOMCAT_HOME/logs/catalina.out

If you do not have $TOMCAT_HOME set you can just use /work/projects/liferay/tomcat/bin or edit the /home/<username>/.bashrc file to add lines such as:

    #Tomcat
    export TOMCAT_HOME=/work/projects/liferay/tomcat

You can change your database to MySQL instead of the default Hypersonic database. Read Liferay Portal 4 - Installation Guide for instructions on how to change to a MySQL database instead of HSQLDB.

Code repository and workspaces #

Liferay trunk #

We will use SVN to pull a local copy of current trunk repository from SourceForge.net .

  • A typical way to have your directory structure would be something like:
    /work/projects/liferay/
  • From the prompt:
    cd /work/projects/liferay/
    svn co {{{svn://svn.liferay.com/repos/public/portal/trunk}}} trunk

(Warning: This is a generic Subversion checkout command which will pull all of trunk (main development line). Please refer to project home page for specific SVN instructions, or use "Browse Repository" link.

  • This will result in the creation of:
    /work/projects/liferay/trunk/
  • From this point on, whenever an you need an update to trunk to the latest code on SourceForge.net:
    cd /work/projects/liferay/trunk
    svn update
  • If you wish to deploy to Tomcat off of trunk, you need to create a file app.server.<username>.properties. Type 'env' at the prompt to see your username. If you want to do this as root:
    su
  • Then type your root password to login as root.
    env
  • You should see 'user' set to 'root' therefore requiring a app.server.root.properties file. This is not a necessary step, but if you make changes to the source code in trunk and want to deploy and see those:
    cd /work/projects/liferay/trunk
    cp app.server.properties app.server.root.properties
    gedit app.server.root.properties
  • In that file you should have something like:
    app.server.type=tomcat
    app.server.parent.dir=/work/projects/liferay
    app.server.tomcat.dir=${app.server.parent.dir}/tomcat
  • If you wish to have clean deploy trunk to tomcat:
    cd /work/projects/liferay/trunk
    ant all
  • If you wish to deploy trunk to tomcat:
    cd /work/projects/liferay/trunk
    ant deploy

Reference: [http://sourceforge.net/svn/?group id=49260

|Backup and restore trunk #

  • Backup: remember to include the hidden directory .svn
    cd /work/projects/liferay/trunk
    tar cvfz mybackup.tar.gz * .svn/*
  • Restore:
    tar xvfz mybackup.tar.gz

Ext environment #

  • In order to build the Ext environment off of trunk, you will need to create a release.<username>.properties file. If you want to login as root and do this:
    su
  • Enter your root password. You will be logged in as root.
    env
  • This will show what 'user' is set to and it should say 'root'
  • Next, we will copy a release.properties file.
    cd /work/projects/liferay/trunk
    cp release.properties release.root.properties
    gedit release.root.properties
  • In that file you should have something like:
    ##
    ## Extension Environment
    ##
    
    lp.ext.dir=/work/projects/liferay/ext
  • Save this file and close the editor
    cd /work/projects/liferay/trunk
    ant clean start build-ext
  • Your Ext environment will be built.
  • If you wish to deploy to Tomcat off of Ext, you need to create a file app.server.root.properties, similar to release.root.properties
    cd /work/projects/liferay/ext
    cp app.server.properties app.server.root.properties
    gedit app.server.root.properties
  • In that file you should have something like:
    app.server.type=tomcat
    app.server.tomcat.dir=/work/projects/liferay/tomcat
  • If you wish to deploy Ext to tomcat:
    cd /work/projects/liferay/ext
    ant deploy

References: http://content.liferay.com/4.0.0/docs/quickstart/ch04s01.html#d0e898]

Eclipse IDE #

    sudo apt-get install eclipse
  • By default Eclipse will use GNU's java instead of Sun's. This will make Eclipse run very slowly and crash from time to time. To solve this problem, we will use Sun's JVM.
  • Install Sun JRE:
    sudo apt-get install sun-java5-jre sun-java5-plugin sun-java5-bin sun-java5-fonts
  • Make Sun's JVM default:
    sudo update-alternatives --config java
  • Choose the line that says
    /usr/lib/jvm/java-1.5.0-sun/jre/bin/java.
  • Edit the JVM Configuration file:
    gksudo gedit /etc/jvm
    # This file defines the default system JVM search order. Each
    # JVM should list their JAVA_HOME compatible directory in this file.
    # The default system JVM is the first one available from top to
    # bottom.
    
    /usr/lib/jvm/java-1.5.0-sun
    /usr/lib/jvm/java-gcj
    /usr/lib/jvm/ia32-java-1.5.0-sun
    /usr
  • Next, we need to tell Eclipse to use this JVM as well. This can be done on systemlevel or userlevel.
  • System:
    gksudo gedit /etc/eclipse/java_home
    # This file determines the search order the Eclipse Platform uses to find a
    # compatible JAVA_HOME. This setting may be overridden on a per-user basis by
    # altering the JAVA_HOME setting in ~/.eclipse/eclipserc.
    
    /usr/lib/jvm/java-1.5.0-sun
    /usr/lib/jvm/java-gcj
    /usr/lib/kaffe/pthreads
    /usr/lib/j2se/1.5
    /usr/lib/j2se/1.4
    /usr/lib/j2sdk1.5-ibm
    /usr/lib/j2sdk1.4-ibm
    /usr/lib/j2sdk1.5-sun
    /usr/lib/j2sdk1.4-sun
  • User:
    gedit ~/.eclipse/eclipserc
    JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun/

reference: [http://ubuntuguide.org/wiki/Ubuntu Edgy#How to install Java Integrated Development Environment .28Eclipse.29

|Workspaces #

Coming Soon!

Debugger #

Coming Soon!

Compiler Performance #

You can use the ECJ compiler with Eclipse instead of Jikes. It greatly improves build and compile performance, and cuts your time by anywhere from several seconds to up to half. You can [http://wiki.liferay.com/index.php/ECJ easily configure this]] in release 4.4.0 and later or you can do the following:

Install ECJ:

    sudo apt-get install ecj-bootstrap

Find ECJ:

    which ecj

You'll probably get something like /usr/bin/ecj

Find Jikes:

    which jikes

You'll probably get something like /usr/bin/jikes

Create a $HOME/bin directory:

    sudo mkdir $HOME/bin

Create a symbolic link that points Jikes to ECJ:

    sudo ln -s /usr/bin/ecj $HOME/bin/jikes

Add it to the PATH by adding this line in $HOME/.bashrc :

    export PATH=$HOME/bin:$PATH

Make sure you reload your .bashrc :

    cd $HOME
    . .bashrc

Or just logout and login again.

Find the new "Jikes":

    which jikes

Should give you something like: /home/username/bin/jikes

Try Jikes at the prompt to check that it is actually calling ECJ:

    Eclipse Java Compiler v_677_R32x, 3.2.1 release
    Copyright IBM Corp 2000, 2006. All rights reserved.

Should cut your build and compile time by up to 50%. ENJOY!

Notes #

Linux Partitions #

You can install Linux onto one big partition, but many use certain partitioning schemes to maximize performance and to make Ubuntu upgrades convenient (i.e. - so you don't lose your personal settings).

Some have a dual-boot setup with Windows and Ubuntu. Here is a particularly good partitioning guide on this scenario:

http://www.psychocats.net/ubuntu/partitioning

Performance #

One benefit of doing a build in linux on a linux partition is the improved performance. On one setup on the same machine, Ubuntu Linux ran an 'ant all' of trunk in 2 minutes vs. Windows which took over 8 minutes.

Package Managers #

This guide used APT, but another useful tool would be the GUI tool that comes with Ubuntu, Synaptic Package Manager. It is under System=>Administration=>Synaptic Package Manager .

General Ubuntu Install Suggestions #

Some find it useful to configure Linux Partitons in this scenario as such:

 /      <== root
 /home  <== personal settings and extra space
 /work  <== development and compiles
 /windows <== windows (NTFS) partition

In this scenario, root has your ubuntu installation, /home has application and personal settings as well as extra space so if you upgrade or reinstall you do not lose those, /work has your Liferay projects and is not too big for faster compiles, and /windows is for your WinXP installation (if you have dual boot)

For more on how to partition, see http://www.psychocats.net/ubuntu/partitioning

Related Articles #

Building and deploying Liferay 4.1 using MySQL on Linux

Development Environment (Fedora Linux)

0 Attachments
48822 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Thanks for this entry! I would love to see this... Sven Ehlert January 27, 2010 4:16 AM
I'm wondering how valid these directions are... Lisa Simpson February 28, 2010 10:27 AM
This information is really a bit old: ubuntu... Paul Leclercq July 29, 2011 9:51 AM

Thanks for this entry! I would love to see this updated with information about the best way to add the deployed Liferay as a project to Eclipse, so that one can easily browse the JSPs. I've created a "Dynamic Web Project" using Eclipse WTP, but the JSP Editor / JSP Validator seems to have problems with the Liferay's 'html' folder.
Posted on 1/27/10 4:16 AM.
I'm wondering how valid these directions are since Ubuntu is now on Karmic Koala and about to release Lucid Lynx
Posted on 2/28/10 10:27 AM in reply to Sven Ehlert.
This information is really a bit old: ubuntu 6.4 while we are using 11.4 and liferay 4.3 while 6.1 is about to come out....
Posted on 7/29/11 9:51 AM.