切换Liferay从Ant到Maven

疏雨过 2012-06-02

默认情况下,Liferay是用的Ant来完成编译,打包部署的,你可以轻易的在SDK中找到相应的Ant脚本,当然了, 我们也可以用Maven来完成这个目标:

首先,我们必须添加liferay相关的maven原型(archetype),在Windows->Preference->Maven->Archetype中:

切换Liferay从Ant到Maven

这样我们的Maven创建向导中就有了 Liferay相关的原型:

我们现在用Maven向导来创建

我们选择liferay-portlet-archetype:

切换Liferay从Ant到Maven

创建完了之后的portlet应该有如下的目录结构:

切换Liferay从Ant到Maven

我们编辑pom.xml ,添加2个属性,一个是liferay.version,一个是liferay.auto.deploy.dir,

最终的pom.xml是这样的:

  1. <?xml version="1.0"?> 
  2.  
  3. <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"> 
  4.     <modelVersion>4.0.0</modelVersion> 
  5.     <groupId>com.charles.liferay</groupId> 
  6.     <artifactId>charles-portlet</artifactId> 
  7.     <packaging>war</packaging> 
  8.     <name>charles-portlet Portlet</name> 
  9.     <version>0.0.1-SNAPSHOT</version> 
  10.     <build> 
  11.         <plugins> 
  12.             <plugin> 
  13.                 <groupId>com.liferay.maven.plugins</groupId> 
  14.                 <artifactId>liferay-maven-plugin</artifactId> 
  15.                 <version>${liferay.version}</version> 
  16.                 <configuration> 
  17.                     <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir> 
  18.                     <liferayVersion>${liferay.version}</liferayVersion> 
  19.                     <pluginType>portlet</pluginType> 
  20.                 </configuration> 
  21.             </plugin> 
  22.             <plugin> 
  23.                 <artifactId>maven-compiler-plugin</artifactId> 
  24.                 <configuration> 
  25.                     <encoding>UTF-8</encoding> 
  26.                     <source>1.5</source> 
  27.                     <target>1.5</target> 
  28.                 </configuration> 
  29.             </plugin> 
  30.             <plugin> 
  31.                 <artifactId>maven-resources-plugin</artifactId> 
  32.                 <configuration> 
  33.                     <encoding>UTF-8</encoding> 
  34.                 </configuration> 
  35.             </plugin> 
  36.         </plugins> 
  37.     </build> 
  38.     <dependencies> 
  39.         <dependency> 
  40.             <groupId>com.liferay.portal</groupId> 
  41.             <artifactId>portal-service</artifactId> 
  42.             <version>${liferay.version}</version> 
  43.             <scope>provided</scope> 
  44.         </dependency> 
  45.         <dependency> 
  46.             <groupId>com.liferay.portal</groupId> 
  47.             <artifactId>util-bridges</artifactId> 
  48.             <version>${liferay.version}</version> 
  49.             <scope>provided</scope> 
  50.         </dependency> 
  51.         <dependency> 
  52.             <groupId>com.liferay.portal</groupId> 
  53.             <artifactId>util-taglib</artifactId> 
  54.             <version>${liferay.version}</version> 
  55.             <scope>provided</scope> 
  56.         </dependency> 
  57.         <dependency> 
  58.             <groupId>com.liferay.portal</groupId> 
  59.             <artifactId>util-Java</artifactId> 
  60.             <version>${liferay.version}</version> 
  61.             <scope>provided</scope> 
  62.         </dependency> 
  63.         <dependency> 
  64.             <groupId>javax.portlet</groupId> 
  65.             <artifactId>portlet-api</artifactId> 
  66.             <version>2.0</version> 
  67.             <scope>provided</scope> 
  68.         </dependency> 
  69.         <dependency> 
  70.             <groupId>javax.servlet</groupId> 
  71.             <artifactId>servlet-api</artifactId> 
  72.             <version>2.4</version> 
  73.             <scope>provided</scope> 
  74.         </dependency> 
  75.         <dependency> 
  76.             <groupId>javax.servlet.jsp</groupId> 
  77.             <artifactId>jsp-api</artifactId> 
  78.             <version>2.0</version> 
  79.             <scope>provided</scope> 
  80.         </dependency> 
  81.     </dependencies> 
  82.     <properties> 
  83.         <liferay.version>6.1.0</liferay.version> 
  84.         <liferay.auto.deploy.dir>D:\Liferay\RI\liferay-portal-6.1.0-ce-ga1\deploy</liferay.auto.deploy.dir> 
  85.     </properties> 
  86. </project> 

相关推荐

知其然知其所以然 / 0评论 2010-10-14