Maven - 将某些资源文件从默认的 src/main/resources 位置排除到 WAR 中

use*_*392 2 war maven

目前,我想在打包时将默认 src/main/resources 文件夹中的一些文件排除到我的 WAR 中

我尝试使用 maven-war-plugin 进行以下配置,但失败了。

<webResources>
  <resource>
    <directory>src/main/resources</directory>
    <targetPath>WEB-INF/classes</targetPath>
    <excludes>
      <exclude>*.xml</exclude>
    </excludes>
  </resource>
</webResources>
Run Code Online (Sandbox Code Playgroud)

...WEB-INF/classes 仍将包含 XML 文件。

怎么办呢?

edr*_*abc 5

正如/sf/answers/191634481/中指出的,从 WAR 包中排除文件的一种快速方法是将它们排除在该build->resources部分中,例如:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>*.xml</exclude>
            </excludes>
        </resource>
    </resources>
    ...
</build>
Run Code Online (Sandbox Code Playgroud)

注意:请注意,以下配置只会影响 Maven 的默认执行(WAR 包、JAR 包等),但不会影响程序集或其他用户配置。