Liferay六年中持续被评为Gartner水平门户魔力象限领导者。 原因是


Latest efforts relating Maven and Liferay have been focused in providing official maven artifacts for Liferay as well as porting our plugins sdk to Maven.

Our goal is to provide our CE releases through our own public repository as well as provide means for our EE customers to install the EE versions artifacts to their local maven repository.

If you have ever worked with enterprise projects using maven you already know how important a local maven repository and proxy is. For those not so familiar with Maven a proxy is a server that proxies your requests to public Maven repositories and caches the artifacts locally for faster and more reliable access. Most maven proxies can also host private repositories used for hosting your company's private artifacts. Having a local proxy / repository makes your maven builds much faster and more reliable than accessing remote repositories that might even sometimes be unavailable.

Installing a maven proxy / repository#

First step is to install and setup Nexus. Nexus is a open source maven repository manager that can proxy to other repositories as well as host repositories. If you just want to try things locally you can skip this step.

  1. Download latest Nexus such as
  2. Follow the installation directions of the Nexus book
  3. Startup nexus
  4. Open your browser to your newly created nexus (if you installed it locally it could be accessed by opening http://localhost:8080/nexus)
  5. Login as administrator (default login is admin / admin123)
  6. Go to Repositories and click Add -> Hosted Repository
  7. Give the repository following information and click save
Repository ID: liferay-ce-releases
Repostory Name: Liferay CE Release Repository
Provider: Maven2 Repository
Repository Policy: Release
  1. Create another hosted repository with following information
Repository ID: liferay-ce-snapshots
Repository Name: Liferay CE Snapshot Repository
Provider: Maven2 Repository
Repository Policy: Snapshot

Now you have a repository ready for Liferay's Maven artifacts. Next step is to configure your maven to be able to upload artifacts to that repository.

Configuring Maven Settings#

Open your $HOME/.m2/settings.xml (if the file does not exist create it). Add the servers segment to your settings.xml

<?xml version="1.0" encoding="UTF-8"?>

You might also want to make your Nexus as your maven proxy. To do that just add following xml segment to your settings.xml right before servers element.

          <name>Local mirror repository</name>

Installing Liferay Artifacts to Repository#

Next we will install the Liferay Maven artifacts to your repository. First you need to checkout Liferay code from the SVN.

svn --username guest co svn:// portal-trunk

Guest user does not require password.

Then create a release.${username}.properties file and add


Build Liferay artifacts by running

ant clean start jar

Now you can deploy the Liferay artifacts to your maven repository by running

ant -f build-maven.xml deploy-artifacts

If you only want to have them locally without a maven repository you can run the install task instead of deploy

ant -f build-maven.xml install-artifacts

Now you can add Liferay dependencies to your maven project. Following artifacts are available:


NOTE portal-impl and portal-web are provided for maven plugins and should never be added as dependency to your Liferay plugins.

Installing the Liferay Maven SDK#

To take full advantage of Maven we are porting the functionality of out ant based Plugins SDK to Maven. To use it you need to install it locally. To install the Liferay maven plugins and archetypes go into support-maven folder and run

mvn install

Now the Liferay Maven SDK is installed and ready to use. We've implemented a portlet archetype and deployer plugin.

Creating a Portlet Plugin#

Move to the folder where you want to create your portlet and run

mvn archetype:generate

From the list select liferay-portlet-archetype and provide your project groupId, artifactId and version for the portlet project.

You're portlet project's pom.xml has two properties and liferay.version. These properties are usually moved to your parent pom.xml or settings.xml so that you don't have to adjust them for every single plugin you create. Set the to point to the Liferay autodeploy directory of your Liferay bundle. This is where the deploy plugin will copy your portlet. Now you are ready deploy your newly created portlet. You can deploy it by running

mvn liferay:deploy

Future Plans#

We are also in the process of adding archetypes for themes, hooks and layouts as well as providing portlet archetypes for different types of portlets like JSP, Spring MVC, JSF etc.

If you are using 5.2.3 CE and want to take advantage of Maven for building Liferay portlets Milen Dyankov a Liferay community member has done also great work on a Maven SDK for 5.2.3 CE. You can find more about it from GitHub

(Extracted from Mika Koivisto's blog)

0 附件
99620 查看
平均 (0 票)
满分为 5,平均得分为 0.0。
讨论主题回复 作者 日期
Service builder doesn't work in the latest... jonathan doklovic 2010年6月17日 下午1:22
Hey Jonathan, have you figured out why it... Jakub Liska 2010年10月20日 下午4:08
the maven-archetype doesn't create WEB-INF/sql... Jakub Liska 2010年10月20日 下午4:52
That's not what I wanted to say :-) the... Jakub Liska 2010年10月20日 下午4:59
Jakub, Were you able to run the service... Brian Ko 2010年11月3日 上午8:16
I was not able to use this notes with liferay... Baptiste Grenier 2010年6月23日 上午4:10
Maven archetype for themes I use maven to build... Sverker Abrahamsson 2010年8月6日 上午7:11
Any update on the Spring/JSF archetypes? Peter Mesotten 2010年10月8日 上午12:26
Hi there, It works great. It created a basic... Brian Ko 2010年11月1日 下午6:14
Please ignore my previous email. I did not see... Brian Ko 2010年11月1日 下午6:21
With Liferay CE 6.0.5, Maven service builder... Shinobi vn 2011年1月13日 下午11:36
Since instructions on this page are not... Petr Vlček 2011年3月25日 上午2:21
Thank you Petr. Exactly what i was looking for.... Tom Mahy 2011年6月2日 上午1:40
Hey all, Hours of Googling on this has not... Lorin Sutton 2011年6月2日 下午12:42
Lorin, did you try...? mvn liferay:build-service Jerry Thome 2011年7月6日 下午12:00
I followed the instructions Petr Vlček added,... Rollin Crittendon 2011年12月2日 上午6:51
I was also wondering for gpg keys do we use... Rollin Crittendon 2011年12月2日 上午7:20
I found my maven settings file had a format... Rollin Crittendon 2011年12月2日 上午8:11
Hello Everyone I'm testing for the first time... Gerald Perellano 2011年12月12日 上午5:42
Hi everybody. Is there any documentation about... David García González 2012年3月19日 上午3:07
It looks like the Maven artifacts have been... Sean Champ 2012年6月30日 上午7:48
Hi, I created a maven-liferay-theme project... Tirthankar Bhadra 2012年8月17日 上午3:56
Hi, I need to use Service Builder but with... Rahul Saraswat 2013年1月10日 上午6:09
Hi Everyone, I need to use Service Builder but... Rahul Saraswat 2013年1月10日 上午6:10
Hi, If I create maven project using liferay... Joga Krish 2013年4月5日 上午4:36

Service builder doesn't work in the latest maven sdk.
It generates code fine, but it does not create the -services.jar or any of the sql scripts that should be packaged with the war.
在 10-6-17 下午1:22 发帖。
I was not able to use this notes with liferay portal 6.0.2 branche, more details in this forum thread:
在 10-6-23 上午4:10 发帖。
Maven archetype for themes
I use maven to build themes, first I have a maven project which creates the base artifacts for _styled, _unstyled and classic themes. Then I create my theme project from an archetype which extend the desired theme.

Under \src\main\webapp\ in my project is the same as _diff in the traditional structure, I find this much easier to work with.

The files can be downloaded from here:­rchetype-1.0.jar

Run first maven in the base project, adjust the path to liferay installation. Then generate the new theme project with the following command line:

mvn archetype:generate -DarchetypeGroupId=com.liferay -DarchetypeArtifactId=theme-archetype -DarchetypeVersion=1.0
在 10-8-6 上午7:11 发帖。
Any update on the Spring/JSF archetypes?
在 10-10-8 上午12:26 发帖。
Hey Jonathan,

have you figured out why it wasn't generating the jar and sql scripts ? Cause I'm using current trunk now, and it still doesn't generate them.
在 10-10-20 下午4:08 发帖以回复 jonathan doklovic
the maven-archetype doesn't create WEB-INF/sql directory and without it doesn't create them....

as to the libraries, in pom definition, portlet-service.jar is marked as provided and util-*.jar are fact it should be the other way around, because during deployment util-*.jars are copied over, but portlet-service.jar should be shipped with portlet...
在 10-10-20 下午4:52 发帖以回复 Jakub Liska
That's not what I wanted to say :-) the "provided" thing, the problem is that the libraries are created with version stamp, and when they are deployed, hot deployer doesn't see them and copy over new util-*.jars to the portlet lib directory and they are doubled there
在 10-10-20 下午4:59 发帖以回复 Jakub Liska
Hi there,
It works great. It created a basic structure for the liferay portlet projects. Now the issue is how we can use the service builder to create the java code which conforms to the maven folder structure so that we can build the war file from maven. Do you have a plan to provide the service builder for maven? Thank you.
在 10-11-1 下午6:14 发帖。
Please ignore my previous email. I did not see the liferay-maven-plugin in pom.xml.
在 10-11-1 下午6:21 发帖以回复 Brian Ko

Were you able to run the service builder (mvn -P build-service install) on the project you created? I got build error as it cannot locate the liferay-lib-5.2.3-r2.pom.

在 10-11-3 上午8:16 发帖以回复 Jakub Liska
With Liferay CE 6.0.5, Maven service builder doesn't create the folder WEB-INF/sql, so you may have issue when deploying the portlet. Create the folder manually and call service builder again (mvn liferay:build-service) will fix this problem.
在 11-1-13 下午11:36 发帖。
Since instructions on this page are not complete (at least for version 6.0.6), I would like to summarize missing points found in related forum posts that helped me to get it working:

1. Install Maven, Ant and Nexus following instructions on this page.
2. Install GPG (
3. Generate GPG key with gpg --gen-key
4. Create your with following contents:

maven.repositor­ # as in settings.xml
gpg.keymame=XXXXX # to get keyname run command gpg --list-keys

5. Build Liferay - ant clean start jar
6. Build javadoc packages - ant -f build-maven.xml jar-javadoc
7. Build source packages - ant -f build-maven.xml jar-sources
8. Deploy all to Nexus - ant -f build-maven.xml deploy-artifacts
在 11-3-25 上午2:21 发帖。
Thank you Petr.
Exactly what i was looking for.

This should be included in the doc.
btw: keymame --> keyname :-)
在 11-6-2 上午1:40 发帖以回复 Petr Vlček
Hey all,

Hours of Googling on this has not been fruitful

So I'm trying the Maven SDK for the first time and just did a simple test:

mvn archetype:generate
selected : 10: remote -> liferay-portlet-archetype (Provides an archetype to create Liferay portlets.)

and did the remaining requested info. The project was created without error.

When I do a "mvn -P build-service compile" though, I continually get:

Profile with id: 'build-service' has not been activated.

mixed into the otherwise successful build process.

I was monkeying with my settings.xml file as was outlined in comments above but after a few failed attempts I realized it was more "monkeying" and less "knowing" so I stopped.

Can someone clarify what should be adjusted where so that the build-services profile will succeed?

Thanks much,
在 11-6-2 下午12:42 发帖以回复 Tom Mahy
Lorin, did you try...?

mvn liferay:build-service
在 11-7-6 下午12:00 发帖以回复 Lorin Sutton
I followed the instructions Petr Vlček added, with the addition from Tom Mahy.

I am using 6.0.6. When I try to deploy I get the following after running "ant -f build-maven.xml deploy-artifacts".

Is there another Nexus configuration step that is needed?
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.4:sign-and-deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.liferay.portal:portal-client:jar:6.0.6 from/to liferay (http://localhost:8081/nexus/content/repositories/liferay-ce-releases): Failed to transfer file: http://localhost:8081/nexus/content/repositories/liferay-ce-releases/com/liferay­/portal/portal-client/6.0.6/portal-client-6.0.6.jar. Return code is: 401
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
在 11-12-2 上午6:51 发帖以回复 Jerry Thome
I was also wondering for gpg keys do we use just the name, say "test" or the UID as the gpg.keyname, as is "test <>"?
在 11-12-2 上午7:20 发帖以回复 Rollin Crittendon
I found my maven settings file had a format issue.

As for the gpg.keyname, it is a hexadecimal value.
在 11-12-2 上午8:11 发帖以回复 Rollin Crittendon
Hello Everyone

I'm testing for the first time the Liferay Maven SDK. And now I have a problem running the service-builder.

With mvn -P build-service package I've got build-service not found error and if
I use mvn liferay:build-service this error comes out:

Failed to execute goal com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service (default-cli) on project inseratsearchpoc: Execution default-cli of goal com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service failed: An API incompatibility was encountered while executing com.liferay.maven.plugins:liferay-maven-plugin:6.0.5:build-service: java.lang.ExceptionInInitializerError: null
realm = plugin>com.liferay.maven.plugins:liferay-maven-plugin:6.0.5
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/gpe/.m2/repository/com/liferay/maven/plugins/liferay-maven-plugin­/6.0.5/liferaymaven-plugin-6.0.5.jar
urls[1] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/portal-impl/6.0.5/portal-im­pl-6.0.5.jar
urls[2] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/portal-service/6.0.5/portal­-service-6.0.5.jar
urls[3] = file:/C:/Users/gpe/.m2/repository/com/liferay/portal/util-java/6.0.5/util-java-6­.0.5.jar
urls[4] = file:/C:/Users/gpe/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.5/plexus-­utils-1.5.5.jar
urls[5] = file:/C:/Users/gpe/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.1/p­lexusinterpolation1.1.jar.......

Does anybody know how can I get it work?

在 11-12-12 上午5:42 发帖。
Hi everybody. Is there any documentation about the goals of liferay plugins?

Where could I read about the configuration of these goals. It could be very useful a page like this, where it is explained the goals of "war" with the options to generate the war:
在 12-3-19 上午3:07 发帖以回复 Gerald Perellano
It looks like the Maven artifacts have been published to the web, obviating the need to download and compile the artifacts separately - there's an announcement dated January 2012 at­facts-released

As well as being available via Sonatype, the artifacts are now also available via the main maven repository under
在 12-6-30 上午7:48 发帖。
I created a maven-liferay-theme project ( com.liferay.maven.archetypes, liferay-theme-archetype version 6.1.10).But the problem is, in the ant theme project, when ever we make any change under the diffs folder and save it,the the sdk starts the build and it same change reflects in the in other folders under docroot except the diffs folder. But unfortunately we are not able to get the same build incase of the maven theme project. Can any one please help on this ?
在 12-8-17 上午3:56 发帖。

I need to use Service Builder but with maven.I am unable to find content on internet regarding this.
Can anyone help.

Thanks & Regards
Rahul Saraswat
在 13-1-10 上午6:09 发帖。
Hi Everyone,

I need to use Service Builder but with maven.I am unable to find content on internet regarding this.
Can anyone help.

My Email ID is

Thanks & Regards
Rahul Saraswat
在 13-1-10 上午6:10 发帖。

If I create maven project using liferay portlet archetype via command prompt, whenever I do changes in the source code do I have to deploy it again before adding the portlet to the liferay portal.
在 13-4-5 上午4:36 发帖以回复 Rahul Saraswat