Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Liferay Builds with ECJ #

ECJ, the Eclipse Compiler for Java, is an open source incremental compiler used by the Eclipse JDT. It is an option for Liferay builds and is in many cases faster than Javac or Jikes. The jar for ECJ is included in Liferay release 4.4.0 and later.

Configure the build to use ECJ #

In release 4.4.0 and later the build.properties file can be modified so ECJ can be used for builds. Simply changing this property is all you need to do, as the jar file for ECJ is included in the release. Here is an example from the build file of release 4.4.2:

     ##
     ## Compiler
     ##
     
     javac.compiler=modern
     #javac.compiler=org.eclipse.jdt.core.JDTCompilerAdapter

Simple uncomment the line, using a build.{user name}.properties file, that uses the JDTCOmpilerAdapter

After doing this, you will get an initial build error message:

   Task cannot continue because ECJ is not installed.
   
   ECJ was automatically installed. Please rerun your task.

This is expected. It has installed the ECJ jar file into your Ant lib directory. Simply rerun your Ant build.

Configure Eclipse IDE to use ECJ #

Even though you're using Eclipse, you're using Ant to build Liferay and Liferay's build is not dependent on ECJ. After changing the build property, if You keep getting the error message:

   Task cannot continue because ECJ is not installed.
   
   ECJ was automatically installed. Please rerun your task.

Do not fear, you simply need to put the ecj.jar file into the lib directory of the Ant plugin directory in your Eclipse install. For example, in my linux install, this directory is:

     /opt/eclipse/plugins/org.apache.ant_1.7.0.v200706080842/lib

Copy the ecj.jar file from the similar lib directory from your Ant install.

Then add ecj.jar to:

     Eclipse Preferences->Ant->Runtime->Classpath->Ant Home  Entries

Tricks for linux #

In the wiki article "Development Environment (Ubuntu Linux)" there is a section on how to do this in an alternative way. Here it is:

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.

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.

This is just an alternative if you are on linux and do not want to install or do not have the jar, or would rather not use the build properties modifications.

0 Attachments
74543 Views
Average (5 Votes)
The average rating is 5.0 stars out of 5.
Comments
Threaded Replies Author Date
Thank you for this entry, the final step to... Gunnar Brinkmann September 19, 2012 1:44 AM
Great article! You saved me a lot of work,... Juanjo Hernández Cánovas November 27, 2012 8:33 AM
Thanks. Habib Zare March 2, 2013 8:48 AM
Great. Solve my problem. Diego Santiviago October 21, 2013 2:29 PM
Ta-Da!! That solved my problem! I've just added... Raja Datla October 7, 2014 1:44 AM

Thank you for this entry, the final step to resolve my problems regarding theme development / deployment (first step: don't let Eclipse deploy themes, use ant tasks)
Posted on 9/19/12 1:44 AM.
Great article! You saved me a lot of work, Thank you.
Posted on 11/27/12 8:33 AM.
Posted on 3/2/13 8:48 AM.
Great. Solve my problem.
Posted on 10/21/13 2:29 PM.
Ta-Da!! That solved my problem! I've just added the ecj.har in Ant run time on Eclipse and that solved my problem. I don't have to do anything else.

FYI - This is JbossAs7 + Liferay 6.1.1
Posted on 10/7/14 1:44 AM.