在pom.xml中我定义了:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>xml</nonFilteredFileExtension>
</nonFilteredFileExtensions>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
和
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
现在问题是没有过滤所有xml文件。有没有办法过滤单个xml文件?
答案 0 :(得分:21)
我不知道为什么Gabor的解决方案不起作用,但我设法解决了这个问题:
首先我删除了nonFilteredFileExtension标记:
<nonFilteredFileExtension>xml</nonFilteredFileExtension>
然后以这种方式修改我的资源:
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/myxml.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
现在,我的单个xml文件已被过滤,其他文件未被过滤器保留。
答案 1 :(得分:11)
对于您可以使用的资源标记包含和排除。只需定义一个掩码,它只适合您的单个文件。见http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
样品:
<project>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/yoursinglefile.xml</include>
</includes>
</resource>
...
</resources>
...
</build>
...
</project>
答案 2 :(得分:7)
这样的事情对我来说很好:
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>my_file.xml</include>
</includes>
</resource>
</resources>
此文档可以帮助我: Apache Maven - Filtering