【问题标题】:Unable to remove specific files from Maven build无法从 Maven 构建中删除特定文件
【发布时间】:2016-08-28 13:17:35
【问题描述】:

我目前正在研究 Maven 构建。我想从我的 Maven 构建中删除特定文件。我目前正在尝试使用以下代码:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <webResources>
            <resource>
                <directory>src/main/resources</directory>
                <!-- override the destination directory for this resource -->
                <targetPath>WEB-INF/classes</targetPath>
                <!-- enable filtering -->
                <filtering>true</filtering>
                <includes>
                    <include>*.pem</include>
                    <include>*.pfx</include>
                    <include>META-INF/jpa-persistence.xml</include>
                    <include>META-INF/spring-persistence.xml</include>
                    <include>com/abc/config/build-config-${propertyenv}.properties</include>
                </includes>
                <excludes>
                    <exclude>%regex[(?!.*${propertyenv}/)*]</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>

我已在我的 POM 中将 propertyenv 定义为属性值:

<properties>
    <propertyenv>abc</propertyenv>
</properties>

我只想要来自com/abc/config 文件夹的abc.properties 文件。但是在构建后所有.properties 文件都存在。请帮忙。

【问题讨论】:

  • @Abhishek 构建配置文件应该如何提供帮助?使用配置文件,您可以使用其中声明的值激活/覆盖设置。如果设置本身已经不做尝试做的事情,这有什么帮助?

标签: maven properties-file


【解决方案1】:

使用packagingExcludespackagingIncludes 参数在最终战争中包含或排除文件

例子:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.6</version>
          ....
    <configuration>
          ....
                <packagingExcludes>
                    WEB-INF/lib/pax-logging-*.jar, WEB-INF/lib/jaxb-*-2.2.7.jar 
                </packagingExcludes>
    </configuration>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 2018-05-18
    • 2014-10-05
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多