ProgrammerBoy
ProgrammerBoy

Reputation: 891

exclude file from maven's resource directory

I am using maven for my spring boot application(1.5 version). There are some files in src/main/resources like abc.properties, app.json. Below are some pointer what i want to achieve.

  1. Exclude these files getting into the jar.
  2. When i run my application through intellij these files should be available in classpath.

I looked at related answers on SO but none matches my case. Any suggestion?

Upvotes: 0

Views: 954

Answers (2)

Adrian Shum
Adrian Shum

Reputation: 40036

My understanding is

  1. You want some config file, that is available in classpath during runtime
  2. Such config file will be changed based on environment

The way I used to do is:

  1. Create a separate directory for such kind of resources, e.g. src/main/appconfig/
  2. Do NOT include this in POM's resources (i.e. they are not included in resulting JAR)
  3. In IDE, add this directory manually as source folder (I usually put this in testResource in POM. When I use Eclipse + M2E, testResources will be added as source folder. Not sure how IntelliJ though)

For point 2, I used to do it slightly differently. Instead of excluding, I will include in the result JAR but in a separate directory (e.g. appconfig-template), so that people using the application can take this as reference to configure their environment.

An alternative of 3 is: create a separate profile which include appconfig as resource. Use this profile only for your IDE setup but not building your artifact.

Upvotes: 0

Jens
Jens

Reputation: 69440

you can use the resouce tag in maven pom file:

  <resources>
      <resource>
        <directory>[your directory]</directory>
        <excludes>
          <exclude>[non-resource file #1]</exclude>
          <exclude>[non-resource file #2]</exclude>
          <exclude>[non-resource file #3]</exclude>
          ...
          <exclude>[non-resource file #n]</exclude>
        </excludes>
      </resource>
      ...
    </resources>

For more informations see: https://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html

Upvotes: 2

Related Questions