切换Liferay从Ant到Maven

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

编辑我们的liferay应用,比如我们需要显示一些内容,所以更改view.jsp:


  1. <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> 
  2.  
  3. <portlet:defineObjects /> 
  4.  
  5. This is the <b>charles-portlet</b>
  6. This is the portlet created by charles using maven. 

 

我们创建一个Maven配置来编译,打包,部署之,如下图:

切换Liferay从Ant到Maven

 

最终控制台正式编译,打包,部署:


  1. ... 
  2.  
  3. [DEBUG] Configuring mojo com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:deploy from plugin realm ClassRealm[plugin>com.liferay.maven.plugins:liferay-maven-plugin:6.1.0, parent: sun.misc.Launcher$AppClassLoader@11b86e7] 
  4. [DEBUG] Configuring mojo 'com.liferay.maven.plugins:liferay-maven-plugin:6.1.0:deploy' with basic configurator --> 
  5. [DEBUG]   (f) autoDeployDir = D:\Liferay\RI\liferay-portal-6.1.0-ce-ga1\deploy 
  6. [DEBUG]   (f) warFile = D:\Charles\Eclipse_Workspace\charles-portlet\target\charles-portlet-0.0.1-SNAPSHOT.war 
  7. [DEBUG]   (f) warFileName = charles-portlet-0.0.1-SNAPSHOT.war 
  8. [DEBUG] -- end configuration -- 
  9. [INFO] Deploying charles-portlet-0.0.1-SNAPSHOT.war to D:\Liferay\RI\liferay-portal-6.1.0-ce-ga1\deploy 
  10. [INFO] ------------------------------------------------------------------------ 
  11. [INFO] BUILD SUCCESS 
  12. [INFO] ------------------------------------------------------------------------ 
  13. [INFO] Total time: 1:18.604s 
  14. [INFO] Finished at: Fri Jun 01 12:50:47 CST 2012 
  15. [INFO] Final Memory: 5M/12M 
  16. [INFO] ------------------------------------------------------------------------ 

看出被打包的portlet叫 charles-portlet-0.0.1-SNAPSHOT.war

并且部署到了LIFERAY_HOME下deploy目录中

 

我们启动Liferay,和预期一样

切换Liferay从Ant到Maven





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/884674,如需转载请自行联系原作者

上一篇:Joomla是否支持MariaDB数据库?


下一篇:ps 利用液化滤镜制作溶解的相机海报