2

I'm trying to achieve the following distribution for my application, and I'm following this question as guideline

dist/
|-- application-1.0.jar
|-- conf/
    |-- application.properties
    |-- log4j.properties
|-- lib/
    |-- *.jar

My src/main/resources looks like following

resources/
|-- to.be.packaged.inside.jar
|-- to.be.packaged/
|   |-- also
|-- conf/
    |-- application.properties
    |-- log4j.properties

Now, I want to exclude the whole conf folder from being packaged in the JAR (but placed in the target folder).

I tried the following configuration to maven-jar-plugin

<excludes>
  <exclude>conf/*</exclude>
</excludes>

However, this still packages an empty conf folder inside the JAR. How do I exclude the folder and the content?

Tuomas Toivonen
  • 21,690
  • 47
  • 129
  • 225

1 Answers1

3

With conf/* you're only excluding the matching files, it doesn't match the conf directory. By added <exclude>conf</exclude> the directory will be excluded as well.

However, you should ask yourself: should these files be available on the classpath? I would expect the conf-directory to be a directory in the project-root (i.e. <project-root>/conf ), which also means a cleaner pom because you don't have to exclude resources.

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • I tried only `conf`, but in that case nothing was excluded. And what do you mean by the cleaner pom? – Tuomas Toivonen Oct 20 '17 at 13:41
  • Be aware that ALL directories and files are evaluated, so only conf is not enough.`conf/application.properties` doesn't match the exclude-pattern, so it is included. WRT the cleaner pom, you don't have to add custom configuration. Sure, it is only a couple of lines, but by moving the conf-folder the configuration is also isolated from the classpath, which is a good thing when thinking of externalizing configuration. – Robert Scholte Oct 20 '17 at 14:05
  • @TuomasToivonen what the answer ment is that you need to add the second exclude in addition to the existing one. So you will have 2 exclude items: `conf/*` and `conf` – hidralisk Mar 02 '21 at 19:48