In order to get started with Maven you need to have Maven(m2e Plugin) in your eclipse or you can have external tools also for it. As we all are quiet acquainted with liferay plugin-sdk environment for creating portlet plugin project, we are going to provide same kind of functionality in Maven also by implementing then project in Maven SDK .
Prerequisite for creating the liferay plugin portlet using maven sdk.
- Eclipse with (m2e plugin) or simply you can use liferay developer studio 2.0 (Liferay IDE 2.0 provides the maven sdk as well as Ant plugin sdk)
- Liferay bundled Server (I am using Liferay 6.2 with tomcat bundle)
In this example i am not using Liferay developer studio for creating the project and also i am not using Liferay IDE. I will simply use m2e plugin in eclipse.
Steps for creating liferay portlet plugin with Maven SDK:
Step 1. Select the new project wizard in eclipse, choose maven project and click on next.
Image may be NSFW.
Clik here to view.
Step 2. Click on next without selecting or deselecting any checkbox.
Step 3. Select the liferay-portlet-archetype and the version (i am using 6.2.0-RC5 version) according to your liferay server.
(if the archetype is not listing in your eclipse it means your eclipse is not downloaded the latest archetype or you can follow this article to download the archetype in your eclipse m2e plugin)
Image may be NSFW.
Clik here to view.
Click on next.
Step 4. provide the group id, artifact id and package information to your project, and click on finish button.
Image may be NSFW.
Clik here to view.
It will create the maven project with the below structure. just look the structure, the web app structure is similar to liferay web app structure created with plugin sdk. only the difference is build files structure. this project structure has maven supported files(pom.xml) in place of ant suppported files (build.xml) which you will find in plugin sdk project.
Image may be NSFW.
Clik here to view.
Step 5. Now have a look at pom.xml. You will find all the maven plugins, dependencies are already defined. This is defined because of the archetype selection while creating the project. but it has some limitation, the maven archetype does not set the version of liferay in pom.xml and some other properties also not set by default. add the below properties in your pom.xml.
<properties>
<liferay.version>6.2.0-RC5</liferay.version>
<liferay.auto.deploy.dir>D:/Personal work/sandbox/liferay-portal-6.2.0-ce-ga1/deploy</liferay.auto.deploy.dir>
<liferay.maven.plugin.version>6.2.0-RC5</liferay.maven.plugin.version>
<liferay.app.server.lib.global.dir>D:/Personal work/sandbox/liferay-portal-6.2.0-ce-ga1/tomcat-7.0.42/lib/ext</liferay.app.server.lib.global.dir>
</properties>
Now your pom.xml will be like below.
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>liferay-test-portlet</artifactId>
<packaging>war</packaging>
<name>liferay-test-portlet Portlet</name>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>build-css</goal>
</goals>
</execution>
</executions>
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-bridges</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-taglib</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${liferay.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<liferay.version>6.2.0-RC5</liferay.version>
<liferay.auto.deploy.dir>D:/Personal work/sandbox/liferay-portal-6.2.0-ce-ga1/deploy</liferay.auto.deploy.dir>
<liferay.maven.plugin.version>6.2.0-RC5</liferay.maven.plugin.version>
<liferay.app.server.lib.global.dir>D:/Personal work/sandbox/liferay-portal-6.2.0-ce-ga1/tomcat-7.0.42/lib/ext</liferay.app.server.lib.global.dir>
</properties>
</project>
now your pom.xml is fine to build the project.
Step 6. Right click on your project in eclipse and select Run As –> Maven install. then maven will connect tp the central repository and download all the dependency to your local m2 repository. it will take time to download dependencies for first time. for next time it will not take much time to build your application.
Image may be NSFW.
Clik here to view.
Step 7. Now your war file of portlet plugin project will be created in the target folder. you can manually copy the war file to deploy folder of your server.
Image may be NSFW.
Clik here to view.
You can use maven goal to deploy your app.
Mavan goals for Liferay plugin
- liferay:deploy
- liferay:build-service
- liferay:build-wsdd
- liferay:direct-deploy
- liferay:build-ext
- liferay:build-lang
- liferay:theme-merge
- liferay:build-thumbnail
If you want to deploy your app using maven goal then use the below command from command line.
mvn clean package liferay:deploy
If you you are using eclipse then follow the step
Step 1. right click on your project and select run as –> maven build as screen below
Image may be NSFW.
Clik here to view.
Step 2. provide the goal and click on run button. this will clean the old build and create new war file and deploy it in the server.
Image may be NSFW.
Clik here to view.
in the next article we will see how to create a service builder project in maven sdk.
Thanks
The post Liferay project with Maven SDK and eclipse appeared first on CodingLoading.