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的结果,我收到了带有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>

最新更新