设为首页 收藏本站
查看: 716|回复: 0

[经验分享] maven 常用插件汇总

[复制链接]

尚未签到

发表于 2017-2-28 08:35:08 | 显示全部楼层 |阅读模式
  http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
  http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin
  http://www.infoq.com/cn/news/2011/05/xxb-maven-8-plugin
  http://yingzhuo.iteye.com/blog/1185371

Maven常用插件
    博客分类:
  • Maven

maven
Maven常用插件
1) 通用

  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-compiler-plugin</artifactId>  
  •     <version>2.3.2</version>  
  •     <configuration>  
  •         <source>1.6</source>  
  •         <target>1.6</target>  
  •         <encoding>UTF-8</encoding>  
  •     </configuration>  
  • </plugin>  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-resources-plugin</artifactId>  
  •     <version>2.5</version>  
  •     <configuration>  
  •         <encoding>UTF-8</encoding>  
  •     </configuration>  
  • </plugin>  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-surefire-plugin</artifactId>  
  •     <version>2.9</version>  
  •     <configuration>  
  •         <skipTests>true</skipTests>  
  •         <testFailureIgnore>flase</testFailureIgnore>  
  •     </configuration>  
  • </plugin>  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-dependency-plugin</artifactId>  
  •     <version>2.3</version>  
  •     <configuration>  
  •         <outputDirectory>dependencies</outputDirectory>  
  •     </configuration>  
  • </plugin>  
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<skipTests>true</skipTests>
<testFailureIgnore>flase</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>dependencies</outputDirectory>
</configuration>
</plugin>

2) 打包

  • <!-- mvn war:war -->  
  • <plugin>  
  •     <artifactId>maven-war-plugin</artifactId>  
  •     <version>2.1.1</version>  
  •     <configuration>  
  •         <packagingExcludes>WEB-INF/web.xml</packagingExcludes>  
  •         <webXml>WebContent/WEB-INF/web.xml</webXml>  
  •         <outputDirectory>target</outputDirectory>  
  •         <warName>client</warName>  
  •         <warSourceDirectory>WebContent</warSourceDirectory>  
  •     </configuration>  
  • </plugin>  
  • <!-- mvn jar:jar -->  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-jar-plugin</artifactId>  
  •     <version>2.3.2</version>  
  •     <configuration>  
  •         <excludes>  
  •             <exclude>**/impl/*.class</exclude>  
  •         </excludes>  
  •     </configuration>  
  • </plugin>  
  • <!-- mvn source:jar -->  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-source-plugin</artifactId>  
  •     <version>2.1.2</version>  
  •     <configuration>  
  •         <excludes>  
  •             <exclude>**/impl/*.java</exclude>  
  •         </excludes>  
  •     </configuration>  
  • </plugin>  
  • <!-- mvn ejb:ejb -->  
  • <plugin>  
  •     <groupId>org.apache.maven.plugins</groupId>  
  •     <artifactId>maven-ejb-plugin</artifactId>  
  •     <version>2.3</version>  
  •     <configuration>  
  •         <ejbVersion>3.0</ejbVersion>  
  •     </configuration>  
  • </plugin>  
<!-- mvn war:war -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
<webXml>WebContent/WEB-INF/web.xml</webXml>
<outputDirectory>target</outputDirectory>
<warName>client</warName>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<!-- mvn jar:jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
<exclude>**/impl/*.class</exclude>
</excludes>
</configuration>
</plugin>
<!-- mvn source:jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<configuration>
<excludes>
<exclude>**/impl/*.java</exclude>
</excludes>
</configuration>
</plugin>
<!-- mvn ejb:ejb -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.0</ejbVersion>
</configuration>
</plugin>

3) 部署

  • <!-- mvn package jboss:hard-undeploy jboss:hard-deploy -->  
  • <plugin>  
  •     <groupId>org.codehaus.mojo</groupId>  
  •     <artifactId>jboss-maven-plugin</artifactId>  
  •     <version>1.5.0</version>  
  •     <configuration>  
  •         <jbossHome>D:\apps\jboss-5.1.0.GA</jbossHome>  
  •         <serverName>default</serverName>  
  •         <fileName>target/${project.artifactId}-${project.version}.jar</fileName>  
  •     </configuration>  
  •     <executions>  
  •         <execution>  
  •             <id>redeploy</id>  
  •             <phase>install</phase>  
  •             <goals>  
  •                 <goal>hard-undeploy</goal>  
  •                 <goal>hard-deploy</goal>  
  •             </goals>  
  •         </execution>  
  •         <execution>  
  •             <id>undeploy</id>  
  •             <phase>clean</phase>  
  •             <goals>  
  •                 <goal>hard-undeploy</goal>  
  •             </goals>  
  •         </execution>  
  •     </executions>  
  • </plugin>  
<!-- mvn package jboss:hard-undeploy jboss:hard-deploy -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jboss-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<jbossHome>D:\apps\jboss-5.1.0.GA</jbossHome>
<serverName>default</serverName>
<fileName>target/${project.artifactId}-${project.version}.jar</fileName>
</configuration>
<executions>
<execution>
<id>redeploy</id>
<phase>install</phase>
<goals>
<goal>hard-undeploy</goal>
<goal>hard-deploy</goal>
</goals>
</execution>
<execution>
<id>undeploy</id>
<phase>clean</phase>
<goals>
<goal>hard-undeploy</goal>
</goals>
</execution>
</executions>
</plugin>

4) Jetty

  • <plugin>  
  •     <groupId>org.mortbay.jetty</groupId>  
  •     <artifactId>maven-jetty-plugin</artifactId>  
  •     <version>6.1.10</version>  
  •     <configuration>  
  •         <scanIntervalSeconds>10</scanIntervalSeconds>  
  •         <stopKey>foo</stopKey>  
  •         <stopPort>9999</stopPort>  
  •     </configuration>  
  •     <executions>  
  •         <execution>  
  •             <id>start-jetty</id>  
  •             <phase>pre-integration-test</phase>  
  •             <goals>  
  •                 <goal>run</goal>  
  •             </goals>  
  •             <configuration>  
  •                 <scanIntervalSeconds>0</scanIntervalSeconds>  
  •                 <daemon>true</daemon>  
  •             </configuration>  
  •         </execution>  
  •         <execution>  
  •             <id>stop-jetty</id>  
  •             <phase>post-integration-test</phase>  
  •             <goals>  
  •                 <goal>stop</goal>  
  •             </goals>  
  •         </execution>  
  •     </executions>  
  • </plugin>  
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
  http://hanqunfeng.iteye.com/blog/1300098
  http://qa.taobao.com/?p=13201
maven常用插件和mvn test命令
    2011年6月30日 由 luanjia  留言 &raquo;
   自定义构建Maven项目,需要包括额外的插件或者配置已存在的插件参数。
1. maven-compiler-plugin 指定JDK版本和编码方式
  compiler插件能解决2个问题:
  第一: maven 2.1默认使用jdk 1.3来编译,这个版本不支持注解,compiler插件可以指定JDK版本为1.6,解决这个问题。
  第二:windows平台默认使用GBK编码,如果工程编码为utf8,也需要在compiler插件中指出,否则按GBK编码,也会出问题
  <plugins>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
  <source>1.6</source>
  <target>1.6</target>
  <encoding>UTF8</encoding>
  </configuration>
  </plugin>
  </plugins>
2. maven-war-plugin 打war包在web子项目中指定
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.1-beta-1</version>
  <configuration>
  <attachClasses>true</attachClasses>
  </configuration>
  </plugin>
  <attachClasses>true</attachClasses> 可以把JAR文件和标准的WAR文件同时安装到Maven仓库中
3. 单元测试插件 maven-surefire-plugin
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
  <argLine>-Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m</argLine>
  <excludes>
  <exclude>**/TestConstants.java</exclude>
  </excludes>
  <forkMode>always</forkMode>
  </configuration>
  </plugin>
  <argLine>-Xmx1024m -XX:PermSize=256m  -XX:MaxPermSize=256m</argLine>调整JVM(-Xmx1024m)和 PermSize(-XX:PermSize=256m -XX:MaxPermSize=256m)内存
  <excludes>
  <exclude>**/TestConstants.java</exclude>
  </excludes>
  运行测试脚本时不执行TestConstants.java文件
  <forkMode>always</forkMode>
  Maven运行测试用例时,是通过调用maven的surefire插件并fork一个子进程来执行用例的。forkmode属性中指明是要为每个测试创建一个进程,还是所有测试在同一个进程中完成。
  forkMode可设置值有 “never”, “once”, “always” 和 “pertest”。
  pretest: 每一个测试创建一个新进程,为每个测试创建新的JVM是单独测试的最彻底方式,但也是最慢的,不适合hudson上持续回归
  once:在一个进程中进行所有测试。once为默认设置,在Hudson上持续回归时建议使用默认设置。
  always:在一个进程中并行的运行脚本,Junit4.7以上版本才可以使用,surefire的版本要在2.6以上提供这个功能,其中 threadCount执行时,指定可分配的线程数量。只和参数parallel配合使用有效。默认:5。
  <forkMode>always</forkMode>
  <parallel>methods</parallel>
  <threadCount>4</threadCount>
4 .Resource插件
  <filters>   
  <filter>${user.home}/asssd.properties</filter>
  </filters>
  <resources>
  <resource>
  <directory>src/main/resources</directory>
  <filtering>true</filtering>
  <includes>
  <include>**/*</include>
  </includes>
  </resource>
  <resource>
  <directory>src/main/java</directory>
  <includes>
  <include>**.xml</include>
  </includes>
  </resource>
  </resources>
  运行打包命令时,将src/main/resources中的所有文件和src/main/java目录下的所有.xml文件打到jar包中。
  其中filters过滤器的作用是将所有引用文件中的${变量名称},替换成antx.properties文件中的变量值。要使用过滤器时,首先需要设置过滤器:
  <filters>   
  <filter>${user.home}/antx.properties</filter>
  </filters>
  然后再启动过滤器, true需要过滤,false不需要过滤:
  <filtering>true</filtering>
5、Maven常用命令
  1、运行应用程序中的单元测试:mvn test或mvn test -Dtest=***Test, 其中“***Test”为被测试用例的类名(不需要输入.java)
  打开控制台,进入测试工程所在目录:D:\workspace-sell\sell-qatest路径;输入mvn test命令后,开始执行sell-qatest中的所有测试脚本,并将信息输出到控制台。
  如果要单独运行一个测试类里的用例,如 publishAuctionTest.java,则可以运行 mvn test -Dtest=publishAuctionTest
  2、清除目标目录中的生成结果:mvn clean(清除taget文件夹中内容)
  3、在本地repo中安装jar:mvn install。运行命令后工程根目录下生成target文件夹,文件夹内存放jar包,class文件夹等内容。本地仓库repo中生成工程jar包目录。
  4、将工程打包:mvn package。运行命令后工程根目录下生成target文件夹,文件夹内存放jar包,class文件夹等内容。
  5、生成Eclipse项目文件:mvn  eclipse:eclipse。运行命令后生成eclipse工程,项目的根目录下产生.project、.classpath文件和target文件 夹。将该工程导入到eclipse中:打开eclipse,通过file->import,导入到eclipse中。
  6、清除Eclipse工程:mvn eclipse:clean。.classpath和.project文件会被删除。
  7、在运行install 或package时,测试代码不被执行:
  第一种方法:在cmd运行mvn install 或mvn package 命令后加上-Dmaven.test.skip=true 。
  例如:mvn install -Dmaven.test.skip=true
  第二种方法:在pom.xml文件的maven-surefire-plugin插件中添加参数:<skip>true</skip>
  <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <inherited>true</inherited>
  <configuration>
  <skip>true</skip>
  </configuration>
  </plugin>

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-348165-1-1.html 上篇帖子: 学习《The Flex, Spring, and BlazeDS full stack》-1 下篇帖子: HTML5 WebSocket 应用示例
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表