How to filter some folder/files from maven during project's build?

I have this file from spring at ./META-INF/spring/props.properties that I would like not have it in my built .jar when I ran mvn clean package or mvn deploy. I don't want to provide this file for security purposes.

I'm trying to add this on my pom.xml but isn't working.

<build>
  ...
  <resource>
      <directory>META-INF/spring</directory>
      <filtering>true</filtering>
      <includes>
          <include>props.properties</include>
      </includes>
  </resource>
  ...
</build>
enter code here

Answers


You don't want to exclude them from your build, you still want them into your classpath I guess, but you don't want them as part of your final jar, hence your entry point is not the resources element but the Maven Jar Plugin configuration.

Check from its official documentation, here how to exclude resources from the packaging.

Below a possible snippet:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <excludes>
            <exclude>**/spring/props.properties</exclude>
          </excludes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

To exclude a file from being built the pom should look like.

<project>
  ...
  <build>
  ...
    <resources>
       <resource>
          <directory>META-INF/spring</directory>
          <includes>
            <include>**/*</include>
          </includes>
          <excludes>
             <exclude>props.properties</exclude>
          </excludes>
      </resource>
    </resources>
  </build>
</project>

To only exclude it from the jar:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <includes>
            <include>**/*</include>
          </includes>
          <excludes>
             <exclude>META-INF/spring/props.properties</exclude>
          </excludes>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

And for a war file:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <packagingExcludes>META-INF/spring/prop.properties</packagingExcludes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

Need Your Help

Unable to link to boost 1.60 thread library in Visual Studio 2013 on Window 7

c++ visual-studio boost

i am trying to use boost 1.60 thread library in my project with visual studio 2013 on window 7. Following command i used to build boost

The selected wizard could not be started. Plug-in "atg.project" was unable to instantiate class

eclipse atg

Hi I am getting below error while creating an ATG module in Eclipse. I am using eclipseNeon (eclipse-jee-neon-M1-win32-x86_64), JDK 1.8.60, ATG11.2. I have already tried following solutions: