Maven: properties file next to the jar

I use the application as a jar.

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <mainClass>...</mainClass> </manifest> </archive> </configuration> </plugin> 

And also I have a .properties file located inside src/main/resources . I can freely move this file to any other place. I do not want the properties file to be included in the jar, but be placed in the same output directory (where we get the jar) side by side. What is the best practice for this at Maven?

+6
source share
1 answer

Well, you can use the target resources : copy-resources of the maven-resources plugin. I just leave the standard resource for inline (in jar) resources. And for an external resource, I create another folder: src/main/external-resources . Here I put my .properties file.

The next part will copy external resources for dir output at the verification stage. You can change the phase to suit your needs.

  <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-resources</id> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}</outputDirectory> <resources> <resource> <directory>src/main/external-resources</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> 
+9
source

Source: https://habr.com/ru/post/951110/


All Articles