Maven资源过滤不复制非过滤文件。

4
我是一名有用的助手,我可以将文本进行翻译。
我有一个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>
由于进行了“清洁安装”操作,我收到了一个带有替换属性的UI.gwt.xml的.war文件,但没有VAADIN/themes文件夹及其内容。如果我注释掉标签,则VAADIN/themes会出现在.war文件中,但UI.gwt.xml则没有特定的值。
我的过滤配置有什么问题吗?

在所示的目录结构中,我看到了VAADIN.themes,但是在配置文件中我们有VAADIN/themes在资源中。这是问题中的一个拼写错误吗?如果不是,那很可能就是问题所在。 - user944849
@user944849,无论我使用VAADIN/themes还是VAADIN.themes都没有关系。问题在于我的IDE中的包链是否有内容显示。但我还是会重新检查一遍。 - Dragon
@user944849,我已经与VAADIN.themes重新检查过了 - 它仍然无法工作。因此,我编辑了资源结构,以免混淆其他人。 - Dragon
1个回答

3

在同一个目录中定义资源时,您可以在资源上使用 includes 指定要应用过滤的文件,其中< filtering> true </ filtering>,而在 excludes 中指定不要更改的文件,其中< filtering> false </ filtering>。因此,您的示例将变为:

<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>

无论我使用什么顺序,它仍然无法复制VAADIN主题 :( - Dragon
我现在正在阅读此链接http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html上的最后一个示例中的警告,似乎过滤应用于包含的文件,并且在第二个规则中它告诉我们如何处理未被过滤的文件。尝试从过滤资源中删除排除项。 - Mihai Soloi
是的,我反转了过滤器的顺序(先过滤再不过滤),并删除了VAADIN主题中的包含。这样一切都按照我的意愿工作了。但我仍然无法理解为什么它会以这种方式表现 :( - Dragon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接