Build Number Maven Plugin的使用方法

Build Number Maven Plugin的使用方法

1. Build Number Maven Plugin用于获取svn的版本及分支目录,可以将它们用于应用中

2.先在maven的setting.xml中添加仓库,用于下载该插件:

				<pluginRepository>
					<id>codehaus</id>
					<name>codehaus</name>
					<url>http://repository.codehaus.org</url>
				</pluginRepository>

3.在pom文件中使用插件,将svn的版本和分支写入META-INFO/MANIFEST.MF中


4.查看效果:在工程下执行mvn cleaninstall -DskipTests=true,打包后,查看包中的META-INFO/MANIFEST.MF文件:


5.在程序中引用的方法:


System.out.println("Get source branch and version from META-INF/MANIFEST.MF...");
		String appServerHome = arg0.getServletContext().getRealPath("/");
		File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");
		Manifest mf = new Manifest();
		try {
			mf.read(new FileInputStream(manifestFile));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		Attributes atts = mf.getMainAttributes();
		System.out.println("Source Branch: "
				+ atts.getValue("Implementation-Branch"));
		System.out.println("Source Version: "
				+ atts.getValue("Implementation-Version"));

通过控制台,我们看到已经得到了我们想要的版本和分支:



6.参考:

http://mojo.codehaus.org/buildnumber-maven-plugin/

http://apollo.ucalgary.ca/tlcprojectswiki/index.php/Public/Project_Versioning_-_Best_Practices
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值