« Zurück zu Using IntelliJ...

Configuring Liferay as several modules in IntelliJ

Asset-Tag: intellij 6.x

Liferay project in IntelliJ can be organized in several modules. This approach is a bit more complex, but it reflects the real structure of the project.

Before we continue with the IntelliJ configuration, we will assume that Liferay is successfully checked out from svn trunk, compiled, deployed and started at least once.

Note:// you may skip this manual configuration and check fast configuration steps.

Choose Projects Root #

Lets assume that Liferay portal is checked out to liferay/portal folder. As we know, portal by default uses liferay/bundles folder (for app server, deploy folder etc.).

You have two options for IntelliJ projects root:

  1. liferay/portal - project will be created inside portal folder and will not be aware of surrounding folders. This might be a good choice if you work only with portal (no plugins) or you do not use default bundles folder etc.
  2. liferay - project will be created below the portal folder, in the Liferay home folder. Project root therefore contains not only the portal, but also bundles. What is more convenient, you may checkout plugins into liferay/plugins and use the same project for both portal and plugins. Another tip is to put some batch files in the project root so you can quickly access them from IntelliJ.

IntelliJ configuration in both cases is very, very similar. The only difference is in the paths, that's all.

Author of this page (strongly:) recommends the second option and to use liferay (Liferay home) folder as project root.

Create Project #

Start IntelliJ 9.x and create a new project (e.g. File>New Project). Choose 'Create Java project from existing sources'.

On the next screen, choose projects root folder:

or

You have two options for project root, as we already discussed previously.

Automatic configuration #

In most cases, IntelliJ will continue with the automatic project configuration. This saves some time and it is recommended to proceed with the process. Anyhow, even if we skip this automatic configuration, we can manually configure the project later.

Automatic project configuration starts with source folder scanning. Choose all founded folders:

IntelliJ will then search for libraries and will offer to create some library sets. Choose the following:

Then, IntelliJ will search for modules and will try to resolve modules dependencies. Choose the following:

On the next screen choose projects JDK, e.g. JDK 1.6.

Facets detection is the next step (not so important at the moment):

Finally, we are done – press ‘Finish’ and the IDEA project will be created. Note that this is just the end of the automatic project configuration and that we have to tweak it more.

Again, described automatic configuration is not a necessary step and it may be skipped – project can be configured manually later.

Configure Project #

There are few more things to configure and check before we will be able to compile the project from IDEA.

Javac heap #

Let’s give our Java compiler more memory – it will need it:). Go to Settings>Compiler>Java Compiler and put e.g. 512 MB as available amount of Javac heap.

Git access #

During project creation, IDEA will also recognize that project is under Git control. However, we must enter personal credentials, so it is a good time to perform the update (CTRL+T) and configure the Git access.

File encoding #

Set IDE encoding to UTF-8, if not already set.

Ant #

Now we can add some build.xml files to the Ant tool window. For example:

Library sets #

Portal libraries #

Portal library set contains all jars from lib/portal folder. Initially (created during automatic configuration), this set contains attached all jars files. To make things more convenient, let’s remove all attached jars and attach jar folder instead – all portal jars will be automatically managed now on when added or removed.

Development libraries #

Similar as with the Portal libraries, Development library set contain all jars from lib/development folder. Again, we can remove all jars and attach just jar folder (it is more convenient, as explained above):

Development library set will be in 'provided' scope, i.e. only available for compilation.

Global libraries #

Global library set will contain the lib/global folder. For the sake of simplicity, let’s also add portal-client.jar in the same set:

Modules #

This is probably the most important part of the configuration. For each module we will describe its definition and dependencies.

Rename modules #

After automatic project configuration, IntelliJ will create the project with all founded modules. By default, IntelliJ will name modules in uppercase. To make project tree more compact and convenient, it is recommended to rename modules names (SHIFT+F6) to lowercase. During module renaming, IntelliJ will complain with an error that can be completely and safely ignored.

If automatic step is not performed, there is nothing to rename and you will have to create modules manually.

portal #

Root module, no dependencies.

portal-impl #

Content root: liferay\portal\portal-impl

  • Source Folders: src
  • Test Source Folders: test
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • portal (Compile)
  • global (Provided)
  • portal-service (Provided)
  • util-bridges (Compile)
  • util-java (Compile)
  • util-taglib (Compile)
  • registry (Compile) - Only for 7.0 and above

portal-service #

Content root: liferay\portal\portal-service

  • Source Folders: src
  • Test Source Folders: test
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • global (Compile)
  • portal-impl (Test)
  • registry (Compile) - Only for 7.0 and above

portal-web #

Content root: liferay\portal\portal-web

  • Test Source Folders: test

Dependencies:

  • development (Provided)
  • global (Provided)
  • portal-impl (Compile)
  • portal-service (Provided)
  • util-java (Compile)
  • util-taglib (Compile)

support-tomcat #

Content root: liferay\portal\support-tomcat

  • Source Folders: src
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • portal-service (Provided)

util-bridges #

Content root: liferay\portal\util-bridges

  • Source Folders: src
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • global (Provided)
  • portal (Compile)
  • portal-service (Provided)
  • util-java (Compile)

util-java #

Content root: liferay\portal\util-java

  • Source Folders: src
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • global (Provided)
  • portal (Compile)
  • portal-service (Provided)

util-taglib #

Content root: liferay\portal\util-taglib

  • Source Folders: src
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • global (Provided)
  • portal (Compile)
  • portal-impl (Compile)
  • portal-service (Provided)
  • util-java (Compile)

registry #

Ony for 7.0 and above

Content root: /modules/registry/registry-api

  • Source Folders: src/main/java
  • Excluded Folders: classes

Dependencies:

  • development (Provided)
  • global (Provided)
  • portal-service (Provided)
  • util-bridges (Compile)
  • util-java (Compile)

Project tree overview #

Here is how project tree will look like after modules configuration.

Facets #

Generally, we do not need any facet to be able to compile project within IntelliJ. However, we will need a web facet to be deployed with the artifact later.

portal-web #

Compile Project #

Project is now ready to be compiled from IntelliJ: CTRL+F9 and wait for the successful compilation result.

Warning: when compiling for the first time, it may happen that compilation fails, while there are no errors in editor and code. Just invalidate the cache and recompile the project again.

16 Anhänge
45627 Angesehen
Durchschnitt (0 Stimmen)
Die durchschnittliche Bewertung ist 0.0 von max. 5 Sternen.
Kommentare
Antworten im Thread Autor Datum
It would be nice to have a tutorial like this... Julian Dehne 28. Oktober 2014 03:41

It would be nice to have a tutorial like this for newer versions of intellij,
Gepostet am 28.10.14 03:41.