有两种方法;
1. 使用命令行, linux安装subversion, windows安装Slik-Subversion-1.7.9-x64.msi, 然后自己编写maven插件, 在打包的时候调用插件, 插件发送svn info path命令获得版本号, 然后自己写入文件.
2. 使用maven-svn-revision-number-plugin插件,
A: 插件写入/META-INF/MANIFEST.MF信息
[url]http://stackoverflow.com/questions/12144300/how-to-set-version-number-to-java-web-application-using-maven[/url]
B: 参考Maven之使用SVN版本号 [url]http://lanhuidong.iteye.com/blog/1975808[/url]
[img]http://dl2.iteye.com/upload/attachment/0091/2085/091f31b0-7823-3f7f-8237-225985007742.png[/img]
src/main/resources/version.txt
[color=darkblue]repository = ${svn_info.repository}
path = ${svn_info.path}
revision = ${svn_info.revision}
mixedRevisions = ${svn_info.mixedRevisions}
committedRevision = ${svn_info.committedRevision}
status = ${svn_info.status}
specialStatus = ${svn_info.specialStatus}[/color]
打包后这个文件变为
[color=darkblue]repository = https://xxxxxxxxxx/svn/rh_cpm
path = trunk/rh_cpm_web
revision = 3579
mixedRevisions = false
committedRevision = 3579
status =
specialStatus = [/color]
1. 使用命令行, linux安装subversion, windows安装Slik-Subversion-1.7.9-x64.msi, 然后自己编写maven插件, 在打包的时候调用插件, 插件发送svn info path命令获得版本号, 然后自己写入文件.
2. 使用maven-svn-revision-number-plugin插件,
<plugin>
<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>svn-revision-number-maven-plugin</artifactId>
<version>1.13</version>
<configuration>
<entries>
<entry>
<prefix>svn_info</prefix>
<depth>empty</depth>
</entry>
</entries>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.7.8</version>
</dependency>
</dependencies>
</plugin>
A: 插件写入/META-INF/MANIFEST.MF信息
[url]http://stackoverflow.com/questions/12144300/how-to-set-version-number-to-java-web-application-using-maven[/url]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestEntries>
<SVN-Revision>${svn_info.revision}</SVN-Revision>
<SVN-path>${svn_info.path}</SVN-path>
<SVN-mixedRevisions>${svn_info.mixedRevisions}</SVN-mixedRevisions>
<SVN-committedRevision>${svn_info.committedRevision}</SVN-committedRevision>
</manifestEntries>
</archive>
</configuration>
</plugin>
B: 参考Maven之使用SVN版本号 [url]http://lanhuidong.iteye.com/blog/1975808[/url]
[img]http://dl2.iteye.com/upload/attachment/0091/2085/091f31b0-7823-3f7f-8237-225985007742.png[/img]
src/main/resources/version.txt
[color=darkblue]repository = ${svn_info.repository}
path = ${svn_info.path}
revision = ${svn_info.revision}
mixedRevisions = ${svn_info.mixedRevisions}
committedRevision = ${svn_info.committedRevision}
status = ${svn_info.status}
specialStatus = ${svn_info.specialStatus}[/color]
打包后这个文件变为
[color=darkblue]repository = https://xxxxxxxxxx/svn/rh_cpm
path = trunk/rh_cpm_web
revision = 3579
mixedRevisions = false
committedRevision = 3579
status =
specialStatus = [/color]