每个 pom.xml
都有:
<groupId>com.vendor</groupId>
<artifactId>product</artifactId>
<version>1.0.13.0-dev</version> <!-- THIS FIELD -->
<packaging>war</packaging>
version
block 对于与应用程序捆绑在一起很有用,因此用户可以查看和报告它们。
但我不喜欢代码重复,并寻找一种方法来避免将带有版本信息的属性文件放入 VCS (Git/SVN),因为每次我增加版本时,我都必须提交到两个地方 (pom.xml
和 version.properties
)。
我可以通过哪种方式使 pom.xml
中的 version 属性以编程方式在 Java 应用程序中可用?
最佳答案
找到了使用 maven-war-plugin 的解决方案更优雅。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<resource>
<targetPath>WEB-INF/views/jsp</targetPath>
<directory>${basedir}/src/main/webapp/WEB-INF/views/jsp</directory>
<includes>
<include>footer.jsp</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
footer.jsp 然后有:
Application Version: ${project.version}
https://stackoverflow.com/questions/15738553/