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

标签 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 ,我收到带有 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/

相关文章:

java - SonarQube - 防止调用某些静态方法的自定义规则

maven - 为什么在尝试使用 Grails Release 插件中的 publish-plugin 时得到 400

java - 如何在Maven/Vaadin项目的服务器后台运行Java类?

java - 在 FXML 中引用类资源

java - 使用无限循环检查变量变化

Java抽象类构造函数

java - 将 RequestBody 解析为 params

javascript - 在使用 mvn 许可证插件生成的 THIRD-PARTY.txt 文件中添加其他许可证详细信息

java - 如何使用 Jar 文件在 IntelliJ IDEA 中设置运行/调试配置?

java - 从 UI 读取时文件路径错误