默认情况下,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>