0

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
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Valter Silva
  • 16,446
  • 52
  • 137
  • 218

2 Answers2

0

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>
A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
0

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>
tzimnoch
  • 216
  • 1
  • 13