3

我有一个 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 没有特定值。

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

4

1 回答 1

3

在同一资源上定义资源时,您可以在 where 上directory指定要应用过滤的文件,而在 where 上指定不要更改的文件。因此,您的示例将变为: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>
于 2013-07-10T15:16:44.250 回答