Wouldn’t it be nice if you could manage your Liferay Maven projects from Liferay
IDE? You can! Liferay IDE 2.0 introduces the Maven project configurator
m2e-liferay), or the added support of configuring Maven projects as full
Liferay IDE projects. Let’s explore what the Maven project configurator does,
how to install it, and how to install its dependencies.
In order to properly support Maven projects in the IDE, you first need a mechanism to recognize Maven projects as Liferay IDE projects. IDE projects are recognized in Eclipse as faceted web projects that include the appropriate Liferay plugin facet. Therefore, all IDE projects are also Eclipse web projects (faceted projects with web facet installed). In order for the IDE to recognize the Maven project and for it to be able to leverage Java EE tooling features (e.g., the Servers view) with the project, the project must be a flexible web project. Liferay IDE requires that the following Eclipse plugins be installed in order for Maven projects to meet these requirements:
m2e-core(Maven integration for Eclipse)
m2e-wtp(Maven integration for WTP)
When you install the
m2e-liferay plugin, these dependencies are installed by
default. We’ll flesh out the installation process soon, but first, let’s get a
deeper understanding of how these plugins work to give us our IDE/Maven
m2e-core plugin is the standard Maven tooling support for Eclipse. It
provides dependency resolution classpath management and an abstract project
configuration framework for adapters. Also, in order for a Liferay Maven project
to be recognized as a flexible web project, the Maven project must be mapped to
a flexible web project counterpart. The
m2e-wtp plugin. provides project
configuration mapping between the Maven models described in the Maven project’s
POMs and the corresponding flexible web project supported in Eclipse. With these
integration features in place, the only remaining requirement is making sure
m2e-core plugin can recognize the extra lifecycle metadata mappings
necessary for supporting Liferay’s custom goals. Let’s break down the lifecycle
mappings just a bit to get a better understanding of what this means.
Both Maven and Eclipse have their own standard build project lifecycles that are
independent from each other. Therefore, for both to work together and run
seamlessly within Liferay IDE, you need a lifecycle mapping to link both
lifecycles into one combined lifecycle. Normally, this would have to be done
manually by the user. However, with the
m2e-liferay plugin, the lifecycle
metadata mapping and Eclipse build lifecycles are automatically combined
providing a seamless user experience. The lifecycle mappings for your project
can be viewed by right-clicking your project and selecting Properties →
Maven → Lifecycle Mapping.
When first installing Liferay IDE, the installation startup screen lets you
select whether you’d like to install the Maven plugins automatically. Did you
miss this during setup? No problem! To install the required Maven plugins,
navigate to Help → Install New Software. In the Work with field,
insert the following:
Liferay IDE repository - http://releases.liferay.com/tools/ide/latest/milestone/.
m2e-liferay plugin does not appear, this means you already have it
installed. To verify, uncheck the Hide items that are already installed
checkbox and look for
m2e-liferay in the list of installed plugins. Also, if
you’d like to view everything that is bundled with the
uncheck the Group items by category checkbox.
Awesome! The required Maven plugins are installed and your IDE instance is ready to be mavenized! Next, let’s learn how to configure an existing Maven project.
Now your Liferay IDE instance is Maven-ready and you have an existing Maven project. Let’s investigate what is going on under the hood and configure your project. Note, if you’d like to learn how to create a new Maven project in the IDE, visit the Creating Liferay Plugins with Maven section. Furthermore, you can import an existing Maven project by navigating to File → Import → Maven and selecting the location of your Maven project source code.
m2e-core plugin delegates your Liferay Maven plugin’s project
configuration to the
m2e-liferay project configurator. The
configurator then converts your Liferay WAR package into an Eclipse flexible web
project. Next, the
m2e-liferay configurator looks for the Liferay Maven plugin
to be registered on the POM effective model for WAR type packages. If no Liferay
Maven plugin is configured on the effective POM for the project, project
configuration ceases. If the plugin is configured, the project configurator
validates your project’s configuration, checking it’s POM, parent POM, and the
project’s properties. The configurator detects invalid properties and reports
them as errors in the IDE’s POM editor. There are a list of key properties that
your project must specify in order for it to become a valid Liferay IDE project.
The next section titled Using a Parent Plugin Project identifies these
properties and explains how they are used.
There are various ways to satisfy these properties–the Maven profile in the
settings.xml file (recommended), in the User
settings.xml file, in
pom.xml, or in the project
pom.xml directly. You can think of
these choices as a hierarchy for how your Maven plugins receive their
properties. The project
pom.xml overrides the parent
pom.xml, the parent
pom.xml overrides the User
settings.xml file, and the User
file overrides the Global
settings.xml: provides configuration for all plugins belonging to
all users on a machine. This file resides in the
settings.xml: provides configuration for all plugins belonging to a
single user on a machine. This file resides in the
pom.xml: provides configuration for all modules in the parent
pom.xml: provides configuration for the single plugin project.
Note that if a profile is active from your
settings.xml, its values will
override your properties in a POM. If you’d like to specify the properties in a
POM, see the next section Using a Parent Plugin Project for more details.
Here’s an example of what a Maven profile looks like inside the
<profiles> <profile> <id>sample</id> <properties> <plugin.type>portlet</plugin.type> <liferay.version>6.2.0</liferay.version> <liferay.maven.plugin.version>6.2.0</liferay.maven.plugin.version> <liferay.auto.deploy.dir>E:\liferay-portal-tomcat-6.2.0-ce-ga1\deploy</liferay.auto.deploy.dir> <liferay.app.server.deploy.dir>E:\liferay-portal-tomcat-6.2.0-ce-ga1\tomcat-7.0.42\webapps</liferay.app.server.deploy.dir> <liferay.app.server.lib.global.dir>E:\liferay-portal-tomcat-6.2.0-ce-ga1\tomcat-7.0.42\lib\ext</liferay.app.server.lib.global.dir> <liferay.app.server.portal.dir>E:\liferay-portal-tomcat-6.2.0-ce-ga1\tomcat-7.0.42\webapps\ROOT</liferay.app.server.portal.dir> </properties> </profile> </profiles>
Once you have a Maven profile configured in the
file, you can activate the profile by right-clicking on your project →
Properties → Maven and entering the profile IDs that supply the
necessary settings into the Active Maven Profiles text field. For example, to
reference the profile and properties we listed above, you’d enter sample for
the Active Maven Profile. Once you’ve specified all the values, the configurator
m2e-liferay) validates the properties. If there are errors in the
file, the configurator marks them in Liferay IDE’s POM editor. If you fix a
project error, update the project to persist the fix by right-clicking the
project → Maven → Update Project.
After your POM configuration meets the requirements, the configurator installs the Liferay plugin facet and your Maven project is officially a Liferay IDE project!
Once you have your Maven project configured, you may want to execute a specific
Maven goal such as
liferay:build-db that is associated
with your build phase. To access your project’s Maven goals and execute them,
right-click your project → Liferay → Maven and select the goal to
execute. To learn more about Maven’s build lifecycle and plugin goals, visit
Apache’s Build Lifecycle
When working with your
pom.xml file in the IDE, you’ll notice several
different viewing modes to work with:
pom.xml: provides an editable POM as it appears on the file system.
Effective POM: provides a read-only version of your project POM merged with
its parent POM(s),
settings.xml, and the settings in Eclipse for Maven.
Overview: provides a graphical interface where you can add to and edit the
Dependencies: provides a graphical interface for adding and editing
dependencies in your project, as well as modifying the
section of the
Dependency Hierarchy: provides hierarchical view of project dependencies and interactive list of resolved dependencies.
By taking advantage of these interactive modes, modifying and organizing your POM and its dependencies has never been easier!
Next, we’ll consider the benefits of using a Maven parent project with your plugin projects.