Maven resource filtering exclude

2020-07-05 05:27发布

问题:

I have a following maven configuration:

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>keystore.jks</exclude>
                </excludes>
            </resource>
        </resources>

I want keystore.jks to be included in my classes/war application but not to be processed by Maven filtering.

How to change this configuration ?

回答1:

According to the Maven Resource Filtering Documentation, this should work:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <excludes>
            <exclude>keystore.jks</exclude>
        </excludes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>keystore.jks</include>
        </includes>
    </resource>
</resources>


回答2:

Binary filtering

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>3.0.2</version>
  <configuration>
    <nonFilteredFileExtensions>
      <nonFilteredFileExtension>jks</nonFilteredFileExtension>
    </nonFilteredFileExtensions>
  </configuration>
</plugin>


标签: maven