默認情況下,Liferay是用的Ant來完成編譯,打包部署的,你可以輕易的在SDK中找到相應的Ant腳本,當然了, 我們也可以用Maven來完成這個目標:
首先,我們必須添加liferay相關的maven原型(archetype),在Windows->Preference->Maven->Archetype中:
這樣我們的Maven創建向導中就有了 Liferay相關的原型:
我們現在用Maven向導來創建
我們選擇liferay-portlet-archetype:
創建完了之後的portlet應該有如下的目錄結構:
我們編輯pom.xml ,添加2個屬性,一個是liferay.version,一個是liferay.auto.deploy.dir,
最終的pom.xml是這樣的:
- <?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.charles.liferay</groupId>
- <artifactId>charles-portlet</artifactId>
- <packaging>war</packaging>
- <name>charles-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.version}</version>
- <configuration>
- <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
- <liferayVersion>${liferay.version}</liferayVersion>
- <pluginType>portlet</pluginType>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <encoding>UTF-8</encoding>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-resources-plugin</artifactId>
- <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.1.0</liferay.version>
- <liferay.auto.deploy.dir>D:\Liferay\RI\liferay-portal-6.1.0-ce-ga1\deploy</liferay.auto.deploy.dir>
- </properties>
- </project>