1、增加各种插件支持
 
  
  1. 增加项目团队成员(姓名、Email、角色、所属组织等):  
  2. Xml代码   
  3. <developers>   
  4.     <developer>   
  5.         <id>aaronjiu</id>   
  6.         <name>Aaron Jiu</name>   
  7.         <email>aaronjiu_00@mycompany.com</email>   
  8.         <roles>   
  9.             <role>Project Manager</role>   
  10.             <role>Architect</role>   
  11.             <role>Developer</role>   
  12.         </roles>   
  13.         <organization>Mycompany.com</organization>   
  14.         <timezone>+8</timezone>   
  15.     </developer>   
  16. </developers>    
  17. 如果你的团队使用了邮件列表 
  18. Xml代码   
  19. <mailingLists>   
  20.     <mailingList>   
  21.         <name>My App project mailing list</name>   
  22.         <subscribe>dev-subscribe@mycompany.com</subscribe>   
  23.         <unsubscribe>dev-unsubscribe@mycompany.com</unsubscribe>   
  24.         <post>dev@mycompany.com</post>   
  25.         <archive>http://mail-archives.mycompany.com/modmbox/dev/</archive>   
  26.     </mailingList>   
  27. </mailingLists>   
  28.  代码库 
  29. Xml代码   
  30. <scm>   
  31.     <connection>scm:svn:http://svn.mycompany.com/myapp/</connection>   
  32.     <developerConnection>scm:svn:http://svn.mycompany.com/myapp/</developerConnection>   
  33.     <url>http://svn.mycompany.com/viewcvs.cgi/myapp/</url>   
  34. </scm>   
  35.  如果使用了持续集成,那么,添加 
  36. Xml代码   
  37. <ciManagement>   
  38.     <system>Continuum</system>   
  39.     <url>http://integrationserver.mycompany.com/continuum</url>   
  40.     <notifiers>   
  41.         <notifier>   
  42.             <type>mail</type>   
  43.             <address>aaronjiu@mycompany.com</address>   
  44.         </notifier>   
  45.     </notifiers>   
  46. </ciManagement>   
  47. 问题追踪 
  48. Xml代码   
  49. <issueManagement>   
  50.     <system>Bugzilla</system>   
  51.     <url>https://bugzilla.mycompany.com/</url>   
  52. </issueManagement>    
  53.   
  54. 软件所使用协议 
  55. Xml代码   
  56. <licenses>   
  57.     <license>   
  58.         <name>Apache 2</name>   
  59.         <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>   
  60.         <distribution>repo</distribution>   
  61.         <comments>A business-friendly OSS license</comments>   
  62.     </license>   
  63. </licenses>   
  64.   
  65. 添加报表: 
  66. Javadocs 
  67. Xml代码   
  68. <reporting>   
  69.     <plugins>   
  70.         <plugin>   
  71.             <artifactId>maven-javadoc-plugin</artifactId>   
  72.         </plugin>   
  73.     </plugins>   
  74. </reporting>    
  75. JXR:它将会生成源代码的一个有索引和交叉查考的HTML版本 
  76. Xml代码   
  77. <reporting>   
  78.     <plugins>            
  79.         <plugin>   
  80.             <groupId>org.codehaus.mojo</groupId>   
  81.             <artifactId>jxr-maven-plugin</artifactId>   
  82.         </plugin>   
  83.     </plugins>   
  84. </reporting>    
  85. 单元测试报表 
  86. Xml代码   
  87. <reporting>   
  88.     <plugins>            
  89.         <plugin>   
  90.             <groupId>org.codehaus.mojo</groupId>   
  91.             <artifactId>surefire-report-maven-plugin</artifactId>   
  92.         </plugin>   
  93.     </plugins>   
  94. </reporting>    
  95. 测试覆盖率报表 
  96. Xml代码   
  97. <reporting>   
  98.     <plugins>            
  99.         <plugin>   
  100.             <groupId>com.atlassian.maven.plugins</groupId>   
  101.             <artifactId>maven-clover2-plugin</artifactId>   
  102.             <version>2.3.2</version>   
  103.             <configuration />   
  104.         </plugin>   
  105.     </plugins>   
  106. </reporting>    
  107. Changlog报表 
  108. Xml代码   
  109. <reporting>   
  110.     <plugins>            
  111.         <plugin>   
  112.             <groupId>org.codehaus.mojo</groupId>   
  113.             <artifactId>changelog-maven-plugin</artifactId>   
  114.         </plugin>   
  115.     </plugins>   
  116. </reporting>    
  117.   
  118. PMD:代码Review报表 
  119. Xml代码   
  120. <reporting>   
  121.     <plugins>            
  122.         <plugin>   
  123.             <groupId>org.apache.maven.plugins</groupId>   
  124.             <artifactId>maven-pmd-plugin</artifactId>   
  125.             <configuration>   
  126.                 <targetjdk>1.5</targetjdk>   
  127.                 <rulesets>   
  128.                     <ruleset>/rulesets/basic.xml</ruleset>   
  129.                     <ruleset>/rulesets/controversial.xml</ruleset>   
  130.                 </rulesets>   
  131.                 <format>xml</format>   
  132.                 <linkXref>true</linkXref>   
  133.                 <sourceEncoding>utf-8</sourceEncoding>   
  134.                 <minimumTokens>100</minimumTokens>   
  135.             </configuration>   
  136.         </plugin>   
  137.     </plugins>   
  138. </reporting>   
  139. FindBugs: 
  140. Xml代码   
  141. <reporting>   
  142.     <plugins>   
  143.         <plugin>   
  144.             <artifactId>maven-findbugs-plugin</artifactId>   
  145.         </plugin>   
  146.     </plugins>   
  147. </reporting>   
 2、打包源代码
 
  
  1. <build>     
  2.         <plugins>     
  3.             <plugin>     
  4.                 <artifactId>maven-source-plugin</artifactId>     
  5.                 <version>2.1</version>     
  6.                 <configuration>     
  7.                     <attach>true</attach>     
  8.                 </configuration>     
  9.                 <executions>     
  10.                     <execution>     
  11.                         <phase>compile</phase>     
  12.                         <goals>     
  13.                             <goal>jar</goal>     
  14.                         </goals>     
  15.                     </execution>     
  16.                 </executions>     
  17.             </plugin>     
  18.         </plugins>     
  19.     </build>     
 
 3、mvn site出错
最近在使用mvn site时,出现如下问题:
[INFO] SiteToolException: ArtifactNotFoundException: The skin does not exist: Unable to determine the release version

Try downloading the file manually from the project website.

Then, install it using the command:
        mvn install:install-file -DgroupId=org.apache.maven.skins -DartifactId=maven- default-skin -Dversion=RELEASE -Dpackaging=jar -Dfile=/path
/to/file

Alternatively, if you host your own repository you can deploy the file there:
        mvn deploy:deploy-file -DgroupId=org.apache.maven.skins -DartifactId=maven- default-skin -Dversion=RELEASE -Dpackaging=jar -Dfile=/path/t
o/file -Durl=[url] -DrepositoryId=[id]


    org.apache.maven.skins:maven- default-skin:jar:RELEASE
 
原因:使用了不稳定的版本
解决方案:使用 mvn site -Pb2b.unmanaged
 
4、jetty修改端口号
方法1: 在maven项目中经常会用到jetty插件,mvn jetty:run默认启动的是8080端口,tomcat通常占用这个端口,可以手动修改jetty插件的启动端口,命令如下: mvn jetty:run -Djetty.port=9999 或者
mvn -Djetty.port=9999 jetty:run
其他的配置参数如下:
 
ParameterOptionalDefaultDescription
portOptional8080 
contextPathSpecOptional/appThe context path
webAppOptional$project.build.directory/$project.build.finalName.warThe location of the war file
jettyConfigOptional The location of a Jetty xml configuration file,
it will override all other parameters
 
jettyConfig设定jetty配置文件的路径。


方法2: 修改pom文件,jetty插件部分代码如下:
< plugin >
                                 < groupId >org.mortbay.jetty </ groupId >
                                 < artifactId >maven-jetty-plugin </ artifactId >
                                 < version >6.1.6 </ version >
                                 < configuration >
                                         < connectors >
                                             < connector implementation ="org.mortbay.jetty.nio.SelectChannelConnector" >
                                                         < port >9999 </ port >
                                                         < maxIdleTime >60000 </ maxIdleTime >
                                                 </ connector >
                                         </ connectors >
                                 </ configuration >
                         </ plugin >
port节点填写想要启动的端口,我的是9999。jetty插件的官网:
在项目打包或部署的时候,需要跳过test代码部分,命令如下:
mvn -Dmaven.test.skip=true package
 
5、获取java系统属性
java系统属性: mvn help:system
 
  
  1. ....... 
  2. JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_18 
  3. CLASSPATH=.;D:\ProgramFiles\Java\jdk1.6.0_18\lib\dt.jar;D:\ProgramFiles\Java\jdk1.6.0_18\lib\tools.jar 
  4. MAVEN_CMD_LINE_ARGS=help:system 
  5. ALLUSERSPROFILE=C:\Documents and Settings\All Users 
  6. MAVEN_JAVA_EXE="D:\ProgramFiles\Java\jdk1.6.0_18\bin\java.exe" 
  7. ....... 
 
java.home:
 
  
  1. D:\>mvn help:system | find "java.home" 
  2. java.home=D:\ProgramFiles\Java\jdk1.6.0_18\jre 
 
6、google提供的代码生成工具
可以根据传递的键值对进行java代码的生成
< dependency >
       < groupId >com.googlecode.rapid-framework </ groupId >
       < artifactId >rapid-generator </ artifactId >
       < version >4.0.5 </ version >
     </ dependency >
 
7、针对csv文件的操作相关包
< dependency >
       < groupId >com.alibaba.external </ groupId >
       < artifactId >sourceforge.supercsv </ artifactId >
       < version >1.52 </ version >
     </ dependency >
 
8、远程debug时,调试的类的确定
在'Display'视图中,查看当前调用的是那个类。在里面填写内容,选中之后按下ctrl+shift+d执行内容。
例如:
JavadocReport.class.getName().replaceAll("\\.", "/")
 JavadocReport.class.getClassLoader().getResource(JavadocReport.class.getName().replaceAll("\\.", "/") + ".class")
 Thread.currentThread().getContextClassLoader().getResource(JavadocReport.class.getName().replaceAll("\\.", "/") + ".class")
 
9、激活插件的方法
 
groupId:artifactId:version:goal
10、指定加载某个版本的插件
在pom.xml中添加版本相关信息,例如:
 
  
  1. <plugin> 
  2.                 <artifactId>maven-javadoc-plugin</artifactId> 
  3.                 <version>2.8.1-SNAPSHOT</version> 
  4.             </plugin> 
 
 11、developer设置
< developers >
     < developer >
       < name >gl.zggl </ name >
       < id >gl.zggl </ id >
       < email >gl.zggl@alibaba-inc.com </ email >
       < roles >
         < role >Developer </ role >
       </ roles >
       < timezone >+8 </ timezone >
     </ developer >
   </ developers >
 
 12、加入外部仓库
< repositories >
     < repository >
       < id >javaparser </ id >
       < name >JavaParser Repository </ name >
       < url >http://javaparser.googlecode.com/svn/maven2 </ url >
       < snapshots >
         < enabled >false </ enabled >
       </ snapshots >
     </ repository >

   </ repositories >
 
 引入外部依赖:
< dependency >
       < groupId >com.google.code.javaparser </ groupId >
       < artifactId >javaparser </ artifactId >
       < version >1.0.8 </ version >
     </ dependency >
 
 编译:mvn clean package -Pb2b.unmanaged
 
  12、下载依赖的javadoc文档
查找了dependency的官方文档,未发现该命令,具体参考: http://maven.apache.org/plugins/maven-dependency-plugin/