歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

切換Liferay從Ant到Maven

默認情況下,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是這樣的:

  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> 
Copyright © Linux教程網 All Rights Reserved