Getting started with Liferay Maven SDK
This will be the first in series of posts on how to develop Liferay plugins with Maven. In this post we’ll start by creating a new parent project for your plugins and add a portlet project to it. You need to have your maven environment setup with maven and java installed. If you don’t know how to do it I would recommend reading Maven: The Complete Reference from Sonatype, Inc. The chapter 2 has good instructions on how to install maven.
1) Download and install Liferay 6.1.0 bundle. In these posts we assume it’s tomcat bundle but you can use any bundle. I’ll refer to the bundle install location is LIFERAY_HOME from now on. If you need instructions on how to install bundle please refer to Liferay 6.1 User Guide.
2) Create a new directory which will be your project root. This is the location where you would extract Liferay plugins SDK if you were using Ant. Then in that directory create a pom.xml file.
Now you should adjust groupId and artifactId to match you project. Also set the value of liferay.auto.deploy.dir to LIFERAY_HOME/deploy. This is where the plugin is copied for Liferay to deploy. The liferay.version property is set to version of Liferay you are using.
3) Open command prompt or terminal and go to your project directory. Next we’ll going to create a portlet project using a liferay portlet project template. Run
That command will create a list of available project templates like below:
Choose number 24 or what ever the number you have for com.liferay.maven.archetypes:liferay-portlet-archetype
Next you will be asked to choose the template version:
Choose number 6 or what ever you have for 6.1.0 version.
Next you will be asked to provide groupId, artifactId and version:
For groupId use the same as in the first pom.xml. In my case it would be com.liferay.sample. For artifactId I chose sample-portlet as this is the directory it will create. Version should be the same as the project parent. Once you have confirmed the values maven will create the portlet project and add it to you parent project as module automatically.
Now you project structure should be something like this:
4) Go to sample-portlet directory and run
This will compile any classes and packages the portlet war file in target directory.
5) To deploy the portlet into your Liferay bundle you can run
Now you have created your first Liferay plugin project with maven and deployed it to your Liferay bundle.
This post was originally published on Liferay blog.