从maven构建中排除文件

wok*_*oky 9 maven

我有一个带有文件src/main/webapp/META-INF/context.xml的Web应用程序,其中包含一些用于测试数据库的配置.在生产服务器上,此文件位于$ TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml中,我正在使用嵌入式tomcat进行测试,因此我不想打包此文件.我想从maven build中排除这个文件.我试过以下:

<build>
  ...
  <resources>
    <resource>
      <directory>src/main/webapp/META-INF</directory>
      <filtering>true</filtering>
      <excludes>
        <exclude>context.xml</exclude>
      </excludes>
    </resource>
  </resources>
</build>
Run Code Online (Sandbox Code Playgroud)

以及:

<build>
  ...
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <resources>
        <resource>
          <directory>src/main/webapp/META-INF</directory>
          <filtering>true</filtering>
          <excludes>
            <exclude>context.xml</exclude>
          </excludes>
        </resource>
      </resources>
    </configuration>
  </plugin>
</build>
Run Code Online (Sandbox Code Playgroud)

但是文件仍然在war和build目录中打包(例如target/myapp-1.0-SNAPSHOT/META-INF/context.xml).我究竟做错了什么?

Rag*_*ram 18

您可以尝试使用该packagingExcludes参数

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <packagingExcludes>META-INF/context.xml</packagingExcludes>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

要从构建中排除资源,问题中的第一个片段看起来很好,除了resource directory应该指定绝对路径.例如

<directory>${basedir}/src/main/webapp/META-INF</directory>
Run Code Online (Sandbox Code Playgroud)

  • 努力使它远离战争,但它仍然在目标目录中. (2认同)