我有一个 xml 文件,其中包含必须用特定值替换的属性。所以我使用资源过滤来实现这一点。
这是资源结构:
src - main - java - resources - VAADIN -themes - UI.gwt.xml - webapp - WEB-INF
pom.xml 中的资源过滤用法:
<resources> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>false</filtering> <includes> <include>**/VAADIN/themes/*</include> </includes> <excludes> <exclude>**/UI.gwt.xml</exclude> </excludes> </resource> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/UI.gwt.xml</include> </includes> <excludes> <exclude>**/VAADIN/themes/*</exclude> </excludes> </resource> </resources>
由于 clean install
,我收到带有 UI.gwt.xml 的 .war 文件,其中包含已替换的属性,但没有 VAADIN/themes 文件夹及其内容。如果我评论<resources>
然后 VAADIN/themes 出现在 .war 文件中,但是 UI.gwt.xml 没有具体值。
我的过滤配置有什么问题?
最佳答案
在相同的 directory
上定义资源时您可以使用 includes
指定要应用过滤的文件在资源上 <filtering>true</filtering>
,而哪里 <filtering>false</filtering>
您指定不使用 excludes
更改的文件.因此,您的示例将变为:
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<!-- whatever is defined here will have filters applied -->
<include>**/UI.gwt.xml</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<!-- everything in this directory remains the same (no filters) -->
<excludes>
<!-- the excludes found here will be altered by the filters in the first resource set -->
<!-- so we need to define them as excluded from the files that should not have filters applied -->
<exclude>**/UI.gwt.xml</exclude>
</excludes>
</resource>
</resources>
关于java - Maven 资源过滤不会复制未过滤的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17573712/