问题
I have a working standalone JAR maven/spring boot app. It currently has its applicationContext.xml and application.properties files in the JAR within /src/main/resources/. For the sake of easily being able to reconfigure without redeploying, I would like to move the .xml file and the .properties file outside of the jar.
I've setup the maven-antrun-plugin so it copies those resources into the target directory.
However, I'm having difficulty getting these two files (.xml and .properties) excluded from my JAR file.
I've done some research and most guides or discussions talk about adding exclusions into the maven-jar-plugin, but I'm not using maven-jar-plugin. Is there a way to do this with spring-boot-maven-plugin?
I've tried putting the following in my "build" section of my pom file:
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
But the files are still appearing in the /classes folder in the JAR file that maven builds.
Any thoughts or advice as to how to do this?
回答1:
Your posted snippet should exactly do that. You can verify that if you make the maven processes more verbose, probably by building your project with the command mvn -X install
. This command should produce an output like
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-resources-plugin ...
and some lines below the excluded files should be shown.
excludes [**/*.xml, **/*.properties]
But I wonder if just excluding this files is a good way to allow to configure your application. This files are really fundamental. Maybe it would be a better idea to keep the files within the jar and provide some useful defaults. After deployment you can override the value with a different precedence by following this guide.
来源:https://stackoverflow.com/questions/46121704/excluding-xml-and-properties-from-standalone-jar-with-spring-boot-maven-plugin