[英]How do I automatically embed version information into my Java application?
I'm developing a JavaFX 8 application using IntelliJ, Maven and Git. 我正在使用IntelliJ,Maven和Git开发JavaFX 8应用程序。 I have an "about" window which shows the version number and build date. 我有一个“关于”窗口,显示版本号和构建日期。 At the moment, I have to manually change these each time I update the code. 目前,我每次更新代码时都必须手动更改这些内容。
Is there any way I can have my build process automatically generate version and date information and embed this into my code so it shows up in the about window? 有什么方法可以让我的构建过程自动生成版本和日期信息,并将其嵌入到我的代码中,以便它显示在about窗口中?
You can use maven resource filtering. 您可以使用maven资源过滤。
Prepare file eg. 准备文件,例如。 src/main/resources/version.properties
with content: src/main/resources/version.properties
包含内容:
version=${project.version}
and add in your pom: 并添加你的pom:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
<build>
After build maven replace ${project.version}
for current project version. 在构建maven之后,将${project.version}
替换为当前项目版本。
In your project you can read this file and use in your abut window. 在您的项目中,您可以阅读此文件并在邻接窗口中使用。
Read more about build timestamp property: How to access maven.build.timestamp for resource filtering 阅读有关构建时间戳属性的更多信息: 如何访问maven.build.timestamp以进行资源过滤
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.