1、增加各种插件支持
- 增加项目团队成员(姓名、Email、角色、所属组织等):
- Xml代码
- <developers>
- <developer>
- <id>aaronjiu</id>
- <name>Aaron Jiu</name>
- <email>aaronjiu_00@mycompany.com</email>
- <roles>
- <role>Project Manager</role>
- <role>Architect</role>
- <role>Developer</role>
- </roles>
- <organization>Mycompany.com</organization>
- <timezone>+8</timezone>
- </developer>
- </developers>
- 如果你的团队使用了邮件列表
- Xml代码
- <mailingLists>
- <mailingList>
- <name>My App project mailing list</name>
- <subscribe>dev-subscribe@mycompany.com</subscribe>
- <unsubscribe>dev-unsubscribe@mycompany.com</unsubscribe>
- <post>dev@mycompany.com</post>
- <archive>http://mail-archives.mycompany.com/modmbox/dev/</archive>
- </mailingList>
- </mailingLists>
- 代码库
- Xml代码
- <scm>
- <connection>scm:svn:http://svn.mycompany.com/myapp/</connection>
- <developerConnection>scm:svn:http://svn.mycompany.com/myapp/</developerConnection>
- <url>http://svn.mycompany.com/viewcvs.cgi/myapp/</url>
- </scm>
- 如果使用了持续集成,那么,添加
- Xml代码
- <ciManagement>
- <system>Continuum</system>
- <url>http://integrationserver.mycompany.com/continuum</url>
- <notifiers>
- <notifier>
- <type>mail</type>
- <address>aaronjiu@mycompany.com</address>
- </notifier>
- </notifiers>
- </ciManagement>
- 问题追踪
- Xml代码
- <issueManagement>
- <system>Bugzilla</system>
- <url>https://bugzilla.mycompany.com/</url>
- </issueManagement>
- 软件所使用协议
- Xml代码
- <licenses>
- <license>
- <name>Apache 2</name>
- <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
- <distribution>repo</distribution>
- <comments>A business-friendly OSS license</comments>
- </license>
- </licenses>
- 添加报表:
- Javadocs
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
- JXR:它将会生成源代码的一个有索引和交叉查考的HTML版本
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>jxr-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
- 单元测试报表
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>surefire-report-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
- 测试覆盖率报表
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <groupId>com.atlassian.maven.plugins</groupId>
- <artifactId>maven-clover2-plugin</artifactId>
- <version>2.3.2</version>
- <configuration />
- </plugin>
- </plugins>
- </reporting>
- Changlog报表
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>changelog-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
- PMD:代码Review报表
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-pmd-plugin</artifactId>
- <configuration>
- <targetjdk>1.5</targetjdk>
- <rulesets>
- <ruleset>/rulesets/basic.xml</ruleset>
- <ruleset>/rulesets/controversial.xml</ruleset>
- </rulesets>
- <format>xml</format>
- <linkXref>true</linkXref>
- <sourceEncoding>utf-8</sourceEncoding>
- <minimumTokens>100</minimumTokens>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
- FindBugs:
- Xml代码
- <reporting>
- <plugins>
- <plugin>
- <artifactId>maven-findbugs-plugin</artifactId>
- </plugin>
- </plugins>
- </reporting>
2、打包源代码
- <build>
- <plugins>
- <plugin>
- <artifactId>maven-source-plugin</artifactId>
- <version>2.1</version>
- <configuration>
- <attach>true</attach>
- </configuration>
- <executions>
- <execution>
- <phase>compile</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </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
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
其他的配置参数如下:
Parameter | Optional | Default | Description |
port | Optional | 8080 | |
contextPathSpec | Optional | /app | The context path |
webApp | Optional | $project.build.directory/$project.build.finalName.war | The location of the war file |
jettyConfig | Optional | 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 >
< 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
- .......
- JAVA_HOME=D:\ProgramFiles\Java\jdk1.6.0_18
- CLASSPATH=.;D:\ProgramFiles\Java\jdk1.6.0_18\lib\dt.jar;D:\ProgramFiles\Java\jdk1.6.0_18\lib\tools.jar
- MAVEN_CMD_LINE_ARGS=help:system
- ALLUSERSPROFILE=C:\Documents and Settings\All Users
- MAVEN_JAVA_EXE="D:\ProgramFiles\Java\jdk1.6.0_18\bin\java.exe"
- .......
java.home:
- D:\>mvn help:system | find "java.home"
- 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 >
< 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 >
< 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中添加版本相关信息,例如:
- <plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.8.1-SNAPSHOT</version>
- </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 >
< 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 >
< 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 >
< 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/
转载于:https://blog.51cto.com/tianya23/574401