Maven过滤资源并添加项目版本

Chr*_*wes 7 maven-2

这是一种将项目版本编写到文件中的简单过滤方法.

<build>
 <resources>
  <resource>
    <directory>src/main/webapp</directory>
    <includes>
      <include>**/*.version</include>
    </includes>
    <filtering>true</filtering>
  </resource>
 </resources>
</build>
Run Code Online (Sandbox Code Playgroud)

这是项目结构(省略了无关紧要的部分)

????src
?   ????main
?       ????java
?       ?   ???? [...]
?       ????webapp
?           ????META-INF
?           ????WEB-INF
?               ????cfg
?               ????portal.version
???? pom.xml
Run Code Online (Sandbox Code Playgroud)

的内容 portal.version

${project.version}
Run Code Online (Sandbox Code Playgroud)

这应该替换为神器版本pom.xml,但遗憾的是没有任何反应.怎么了?先感谢您

Eug*_*hov 4

当您指定资源元素时,结果过滤内容将复制到 target/classes 文件夹中。要过滤 Web 应用程序资源,您可以配置 maven-war-plugin。

尽管要获取版本,但在大多数情况下最好读取应用程序中的标准 Maven 属性文件,例如META-INF\maven\<groupId>\<artifactId>\pom.properties