Blog Post

...

Build a Liferay portlet war via Maven

Most posts on the internet regarding "How to build a war file of Liferay portlet" topic, cover only Ant tool. I find Maven as a next-gen project build tool and in this post I'll show how to use it to build Liferay portlet war.

There are 2 options to build portlet war: via command line or via eclipse liferay plugin.

To build portlet war via command line:

  1. Add new maven profile (maven settings.xml):
    <profile>
        <id>life</id>
        <properties>
            <plugin.type>portlet</plugin.type>
            <liferay.version>6.2.1</liferay.version>
            <liferay.maven.plugin.version>6.2.1</liferay.maven.plugin.version>
            <!--liferay.auto.deploy.dir>c:\liferay\Tomcat\webapps\deploy2</liferay.auto.deploy.dir-->
            <liferay.app.server.deploy.dir>c:\liferay\Tomcat\webapps</liferay.app.server.deploy.dir>
            <liferay.app.server.lib.global.dir>c:\liferay\Tomcat\lib\ext</liferay.app.server.lib.global.dir>
            <liferay.app.server.portal.dir>c:\liferay\Tomcat\webapps\ROOT</liferay.app.server.portal.dir>
        </properties>
    </profile> 
    
  2. Build usual war file using this command in project dir: mvn clean install
  3. Generated war needs to be modified according to the liferay portlet specification: mvn liferay:direct-deploy -DunpackWar=false -DappServerType=tomcat -DpluginType=portlet -P life

at this step war will be modified and placed to c:\liferay\Tomcat\webapps.

liferay:direct-deploy plugin makes some changes to war: adds information to web.xml, adds liferay files, etc.

 

To build portlet war via eclipse liferay plugin:

  1. Install liferay eclipse plugin.
  2. Project settings -> MAVEN -> Active Maven Profiles, set profile name that was specified for current project (for example "life", see upper part of this document).
  3. Invoke project's maven liferay:direct-deploy command that will copy unpacked war content to deploy.dir. War in this case not generated.

       1

Comments (4)

Tags: liferay maven


Comments:

...

Tony Apr 18, 2015 at 10:02 #

Good post man!

...

Andrey Jan 26, 2016 at 03:27 #

Thanks a lot!

...

Daniel Martínez Cisneros May 12, 2016 at 11:46 #

Great Contribution. Thanks!

...

Stanislav May 12, 2016 at 14:14 #

Daniel, thanks, appreciate this!

Leave a Comment