
Optimal Liferay Core Development with IntelliJ
This Wiki describes how to setup an optimal Liferay core development environment as an alternative to the recommended way based in JRebel:
Setting up a Liferay development environment with IntelliJ #
First make sure you have installed a basic Liferay development environment as described here:
By now you should have installed:
- Java JDK
- Ant
- MySQL
- Liferay sources under ${liferay-dev-home} directory
- A Liferay Tomcat bundle under ${liferay-dev-home}/bundles
If so, you are ready to install and configure a Liferay development environment with IntelliJ.
Install IDEA IntelliJ #
IntelliJ IDEA is one of the most powerful Java IDEs. One of its major strengths is the flexibility of configuration; IntellJ can be integrated into different project organizations and structures.
You can download IntelliJ from their website:
Setting up Liferay modules #
A module in IntelliJ is a functional unit which you can compile, run, test and debug independently. Modules contain everything that is required for their specific tasks: source code, build scripts, unit tests, deployment descriptors, and documentation.
Liferay Portal project may be organized in one single module, where all sources are 'joined' together as they are in the single source folder and all share the same libraries. This approach is easier to configure, but user has to be aware of code dependencies. On the other hand, project can be split in several modules, where each IntelliJ module matches Portals module. This configuration is obviously a bit more complex, however it reflects the real nature of the project.
Fortunately, the optimal configuration for the Liferay Portal project and modules is provided as a part of this guide, so you don't need to do all the work manually.
Before launching IntelliJ we will prepare the IDE by adding some predefined configuration. First we will create a symbolic link to the portal dependencies. This is required in order to make use of the provided configuration:
- Linux:
portal> ln -s portal-impl/classes/com/liferay/portal/deploy/dependencies dependencies-link.iml
- Windows 7 and Vista:
portal> mklink /J dependencies-link.iml portal-impl\classes\com\liferay\portal\deploy\dependencies
- Windows XP and 2000:
You need a special tool to create sym links. For example, Junction
portal> junction dependencies-link.iml portal-impl\classes\com\liferay\portal\deploy\dependencies
Now download and unzip in ${liferay-dev.home}/trunk the configuration file which matches your IntelliJ version:
- intellij configuration for portal version 6 (Intellij IDEA v11)
- intellij config for version 6 (Intellij IDEA v10)
This will add to IntelliJ all the required pre-configured modules for the Liferay Portal project. If you want to learn how to configure it manually, just check this Wiki:
Now run IntelliJ and open a project by selecting your ${liferay-dev.home} folder. First time project is opened, IntelliJ will index all sources and jars; this operation may take some time.
Check the SDK settings #
Open File > Project Structure and in Project Settings > Project check the Project SDK. You might need to create a new SDK configuration. Be sure also to use Oracle JDK, as Open JDK compiler would not be able to compile the project. Also remember always using 1.5 version when working with Liferay, since not all application servers support Java 1.6 or higher, yet.
Build the project #
Once the project is configured, it will be ready for building. IntelliJ can be configured to compile sources to the same output folders as the Ant script does or to use a different folder (which is more common option with IntelliJ). The predefined configuration uses the second option.
Compile the project for the first time (Ctrl + F9). Compilation should complete successfully.
Optimize packaging of web content files during development #
The Auto-package plugin developed by Igor Spasic performs live (background) packaging of web content files during development. It works for all web facets in an IntelliJ project.
Install the plugin using IntelliJ plugin repository:
You just have to install the plugin now, since the pre-configured portal-web module has this option activated by default. Nevertheless, if you require further information, read:
This is how project tree should looks like:
Run/Debug Configuration #
By now we should have all the Liferay Portal project modules installed and configured in IntelliJ, and we should be able to correctly build the project. We will now setup the deployment and run/debug options in IntelliJ.
There are two ways to deploy and run Tomcat from IntelliJ:
- As a local bundle: It requires to invoke Ant tasks for compile/deploy, but we can run and debug the Tomcat app server at ${liferay-dev-home} from IntelliJ. You should use this option when working with Liferay Plugin projects, because they cannot be properly installed when working deploying with artifacts (see next point).
- As an artifact (Exploded Mode): Everything is done with IntelliJ: compiling, deploying etc. This approach allows JSP live deployment, but changes some paths. From now on we will refer to this option as Exploded Mode. This option is specially convenient when working with the Liferay Portal project.
You can learn more about this here:
The configuration files we have installed before have already configured these options. Nevertheless we will go through them in order to check that everything is working fine:
Deployment Artifacts #
An artifact in IntelliJ is a draft that defines the layout of the project output. An artifact can be an archive (jar,war, ear) or a directory. Artifact layouts are constituted from elements of various types such as libraries, facet resources, and other artifacts. These elements are grouped into archives and folders. Once you have configured the artifact layout, you no longer need to get into these details every time you build your application.
As explained above, we will want to run Tomcat from IntelliJ in exploded mode, so that deployment is faster. To make this possible, some artifacts have been pre-configured in the project.
Go to File > Project Structure > Artifacts. After installing the pre-configuration files you should find three artifacts here.
For the two following artifacts check that the correct output path:
- tomcat > portal-service.jar: ${liferay-dev-home}/bundles/tomcat/lib/ext
- liferay-exploded: ${liferay-dev-home}/out/artifacts/liferay_exploded
You can just ignore the tomcat > portal-web exploded since it is not required to setup the exploded mode.
Running the application server from IntelliJ #
Go to Run > Edit Configurations > Tomcat Server. As you see, the pre-configuration files have installed three Tomcat Servers:
- Tomcat : use this to run/debug Liferay as a local bundle
- Tomcat Exploded: use this to run/debug Liferay in exploded mode
- Tomcat Exploded (64bit): use this to run/debug Liferay in exploded mode in 64bit architectures.
For each of them:
- Click "Configure" and check that they are pointing to your Tomcat bundle
- Go to the Startup/Connection tab and check the environment variables:
- JAVA_HOME is defined, so you can run Tomcat with custom JDK (like having Tomcat 7 using java 6, while portal project is build using java 5). If you don't need it, just remove the environment variable definition.
- CATALINA_BASE. It's been deliberately set to blank, so that IntelliJ's own CATALINA_BASE value is overridden and Liferay bundle's value is used instead.
Checkpoint #
At this point of the process, you should be able to:
- Work with the different modules of the Liferay Portal Project
- Run/debug Liferay portal from IntelliJ as a bundle
- Rub/debug Liferay portal from IntelliJ in exploded mode. You can test JSP live deployment by changing some project JSP (e.g login JSP). You just need to save and reload the login page to see the changes (no redeployment of the whole portal needed!).
Advanced development features with IntelliJ #
So far you have installed and configure an optimal Liferay development environment based on IntelliJ. But you can make you development work even more efficient by just installing some IntelliJ plugins:
Save time by avoiding redeploying #
Running Liferay from IntelliJ in exploded mode when developing Liferay Portal code is really convenient since it will save you from building and redeploying the whole project for every change you make. This applies to JSP (and other resources), as well as to Java classes as long as method signatures are not changed.
To support "hot deployment" of deeper changes in Java classes, you have to install IntelliJ JRebel plugin. Just follow these instructions:
Use JIRA bug tracker from IntelliJ #
Liferay uses JIRA as a bug tracker. Install the Atlassian connector for IntelliJ to work with JIRA without leaving IntelliJ:
Easy check the quality and format of your code #
Rearranger Plugin #
Rearranger is a nice IntelliJ plugin that may help with arranging code according to the Liferay Development Style Guide. It can organise methods, variables constructors... as defined in user rules.
Changelist Action Plugin #
Format only the source code of your modified files and save time.
Execute common commands quickly #
Some handy tools for IntelliJ:
- Runner to run 'clean' java code without ant and container
- Invoke common commands with ease using Launchy
Install these tools by following the instructions here:
For more detailed information about how using IntelliJ with Liferay, visit: