Tuesday, January 27, 2015

Create Liferay plugin with Maven (Liferay Portal 6.2)

Step 1:
Download Liferay Portal Maven 6.2.1 CE.
Extract and run: ant install

Step 2:
Download liferay-plugin-maven-support 6.2.2.
Extract and run: mvn clean install

Step 3:
Create Liferay plugin in Liferay IDE with maven build type.
Add pom.xml, 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.example.plugins</groupId>
    <artifactId>test-service</artifactId>
    <packaging>war</packaging>
    <name>test-service Portlet</name>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <liferay.version>6.2.1</liferay.version>
    </properties>
    <build>
        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.liferay.maven.plugins
                                        </groupId>
                                        <artifactId>
                                            liferay-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [6.2.1,)
                                        </versionRange>
                                        <goals>
                                            <goal>build-service</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.liferay.maven.plugins</groupId>
                <artifactId>liferay-maven-plugin</artifactId>
                <version>${liferay.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <id>build-service</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>build-service</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>
<profiles>
<profile>
    <id>Liferay-v6.2-CE-(Tomcat-7)</id>
    <properties>
        <liferay.version>6.2.1</liferay.version>
        <liferay.maven.plugin.version>6.2.1</liferay.maven.plugin.version>
        <liferay.auto.deploy.dir>D:\Liferay\Soft\Liferay 6.2\liferay-portal-6.2-ce-ga2\deploy</liferay.auto.deploy.dir>
        <liferay.app.server.deploy.dir>D:\Liferay\Soft\Liferay 6.2\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\webapps</liferay.app.server.deploy.dir>
        <liferay.app.server.lib.global.dir>D:\Liferay\Soft\Liferay 6.2\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\lib\ext</liferay.app.server.lib.global.dir>
        <liferay.app.server.portal.dir>D:\Liferay\Soft\Liferay 6.2\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\webapps\ROOT</liferay.app.server.portal.dir>
    </properties>
    </profile>
</profiles>
</project>


Now, you can run generate-sources to build Liferay service.
Important: Liferay IDE must fully support Maven plugin type. Should download the newest version.

No comments:

Post a Comment