1.编写pom文件如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<updateReleaseInfo>true</updateReleaseInfo>
</configuration>
</plugin>
</build>
1个release插件1个deploy插件
2.在Nexus中设置用户名和密码
<server>
<id>ci-release</id>
<username>用户名</username>
<password>密码</password>
</server>
<server>
<id>ci-snapshot</id>
<username>用户名</username>
<password>密码</password>
</server>
3.打包管理
<distributionManagement>
<repository>
<id>ci-release</id>
<name>Internal Releases</name>
<url>http://ip地址:端口/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>ci-snapshot</id>
<name>Internal Snapshots</name>
<url>http://192.168.156.138:8088/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
4.设置SVN(scm标签设置SVN、CVS保存地址)
<scm>
<connection>scm:svn:https://IP地址:端口/svn/PSPlatForm_BS/trunk/bj-gbplatform</connection>
<developerConnection>scm:svn:https://IP:端口/svn/PSPlatForm_BS/trunk/bj-gbplatform</developerConnection>
<url>https://192.168.152.88:端口/svn/PSPlatForm_BS/trunk/bj-gbplatform</url>
</scm>
5.以来war包导入(公共代码)依赖时候使用
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<outputDirectory>${dir.tomcat.deploy}</outputDirectory>
<warName>gb-monitor</warName>
<overlays>
<overlay>
<skip>${common.web.overlay.skip}</skip>
<groupId>com.ibs.gbplatform.common.core</groupId>
<artifactId>gbplatform-common-web</artifactId>
<excludes>
<exclude>**/web.xml</exclude>
<exclude>**/WEB-INF/lib/**</exclude>
<exclude>**/GBApp/**</exclude>
<exclude>**/MyDesktop/**</exclude>
<exclude>**/MCApp/**</exclude>
<exclude>**/ibssig*/**</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
6.在pom.xml 中右键Run As→Maven Build运行clean install deploy 打包到Nexus上(修改Ip地址打包不同私服和服务器)
7.Maven的发布版本
在cmd命令下到项目目录下使用mvn release:prepare命令( maven-release-plugin)
详细请看Maven的发布Mvn-release-plugin命令
8.打包发布成功!
9.Maven的常用命令收集
Maven常用命令:
1. 创建Maven的普通java项目:
mvn archetype:create
-DgroupId=packageName
-DartifactId=projectName
2. 创建Maven的Web项目:
mvn archetype:create
-DgroupId=packageName
-DartifactId=webappName
-DarchetypeArtifactId=maven-archetype-webapp
3. 编译源代码: mvn compile
4. 编译测试代码:mvn test-compile
5. 运行测试:mvn test
6. 产生site:mvn site
7. 打包:mvn package
8. 在本地Repository中安装jar:mvn install
9. 清除产生的项目:mvn clean
10. 生成eclipse项目:mvn eclipse:eclipse
11. 生成idea项目:mvn idea:idea
12. 组合使用goal命令,如只打包不测试:mvn -Dtest package
13. 编译测试的内容:mvn test-compile
14. 只打jar包: mvn jar:jar
15. 只测试而不编译,也不测试编译:mvn test -skipping compile -skipping test-compile
( -skipping 的灵活运用,当然也可以用于其他组合命令)
16. 清除eclipse的一些系统设置:mvn eclipse:clean