Maven资源过滤不会复制未过滤的文件

时间:2013-07-10 14:43:59

标签: java maven

我有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的结果,我收到带有替换属性但没有VAADIN / themes文件夹及其内容的UI.gwt.xml的.war文件。如果我发表评论<resources>,那么VAADIN / themes会出现在.war文件中,但是UI.gwt.xml没有特定值。

我的过滤配置有什么问题?

1 个答案:

答案 0 :(得分:3)

在同一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>