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

时间:2010-09-23 15:17:28

标签: maven-2

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

<build>
 <resources>
  <resource>
    <directory>src/main/webapp</directory>
    <includes>
      <include>**/*.version</include>
    </includes>
    <filtering>true</filtering>
  </resource>
 </resources>
</build>

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

├───src
│   └───main
│       ├───java
│       │   └─── [...]
│       └───webapp
│           ├───META-INF
│           └───WEB-INF
│               ├───cfg
│               └───portal.version
└─── pom.xml

portal.version

的内容
${project.version}

这应该替换为pom.xml的工件版本,但遗憾的是没有任何反应。怎么了?提前谢谢

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:2)

要过滤网络资源,您可以使用the filtering capabilities of the war plugin

相关问题