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

时间:2010-11-16 10:53:24

标签: maven war

目前,我希望在打包时将一些文件从默认的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>

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

怎么做?

3 个答案:

答案 0 :(得分:4)

正如https://stackoverflow.com/a/2737635/722997所指出的,从WAR包中排除文件的一种快捷方法是将其排除在build->resources部分,例如:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>*.xml</exclude>
            </excludes>
        </resource>
    </resources>
    ...
</build>

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

答案 1 :(得分:0)

从maven war插件的documentation,您可以按如下方式包含和排除资源:

...
        <configuration>
          <webResources>
            <resource>
              <!-- the default value is ** -->
              <includes>
                <include>**/pattern1</include>
                <include>*pattern2</include>
              <includes>
              <!-- there's no default value for this -->
              <excludes>
                <exclude>*pattern3/pattern3</exclude>
                <exclude>pattern4/pattern4</exclude>
              </excludes>
            </resource>
          </webResources>
        </configuration>
        ...

您是否遵循此操作仍然无效?如果是这样,你可以发布你的pom片段吗?

答案 2 :(得分:0)

这个问题有些晚了,但我只是想做同样的事情,并且发现(使用maven-war-plugin 3.1.0版本),添加:

<packagingExcludes>WEB-INF/classes/*.xml</packagingExcludes>

配置应该按照要求进行操作(它对我来说删除了我们不希望用war文件分发的属性文件)。

相关问题