从pom.xml的应用程序包,包括应用程序版本号 [英] Including application version number from pom.xml to application bundle

查看:184
本文介绍了从pom.xml的应用程序包,包括应用程序版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个的pom.xml 有:

<groupId>com.vendor</groupId>
<artifactId>product</artifactId>
<version>1.0.13.0-dev</version>  <!-- THIS FIELD -->
<packaging>war</packaging>

版本片是用一堆有用的应用程序让用户可以看到并报告它们。

version piece is useful to bunch with application so user can see and report them.

但我不喜欢code重复,并寻找一种方式,以避免把属性文件,版本信息,以VCS(GIT / SVN),因为每次我碰到的版本时,我必须提交到两个地方( pom.xml的 version.properties )。

But I dislike code duplication and look for a way to avoid putting property file with version info to VCS (Git/SVN) because each time I bump version I must commit into two places (pom.xml and version.properties).

我可以做哪种方式版本的pom.xml 属性在Java应用程序编程可用?

Which way can I make version properties from pom.xml programmatically available in Java application?

推荐答案

有一个看的的Maven Resources插件。在你的 version.properties (应该在资源文件夹),定义如 A线版本= $ {project.version} 。请务必开启滤波插件(在所有上面的链接中详细介绍),你应该是好去!

Have a look at the Maven Resources Plugin. In your version.properties (should be in the resources folder), define a line like version=${project.version}. Make sure to turn on filtering for the plugin (all described in detail at the link above) and you should be good to go!

只要运行 MVN资源:资源(或 MVN编译),并检查所生成的文件

Just run mvn resources:resources (or mvn compile) and check the generated file.

这篇关于从pom.xml的应用程序包,包括应用程序版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆