java - 包括从 pom.xml 到应用程序包的应用程序版本号

每个 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.xmlversion.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/

相关文章:

command-line - 如何自动化 Visual FoxPro 项目的构建?

php - 使用 ant 脚本构建 PHP

java - 在 Netbeans 中自动生成源代码和 doc jar

android - 错误 : could not load android-info. txt

java - 如何在构建之前删除 Hudson 工作区?

c++ - 在发布版本中保留调试符号有缺点吗?

visual-studio-2010 - 仅在发布构建期间签署具有强名称的程序集

php - 为什么要编译 PHP 文件?

ant - 如何在命令行上从属性文件加载 Ant 属性?

visual-studio-2010 - 如何阻止 Visual Studio 构建未更改的依赖项?