External configuration files with Maven
What is the Maven approach to deal with config files that will be eventually locat开发者_如何学Goed outside the generated .war/.ear?
I have some config files that during development are in a common-configuration module which is a dependency of my webapp module, but I want some files to be located at different locations during deployment.
You can use the maven-assembly-plugin:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/description.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
the file description.xml should look something like this:
<assembly>
<id></id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>zip</format>
<format>tar</format>
</formats>
<fileSets>
<fileSet>
<directory>../YourProject/${project.build.directory}</directory>
<outputDirectory>/binaries</outputDirectory>
<includes>
<include>YourProject-${version}.war</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/release/docs</directory>
<outputDirectory>/docs</outputDirectory>
</fileSet>
</fileSets>
</assembly>
During deployment you can untar or unzip the generated file. The content of the tar/zip-file will look something like this:
/binaries/YourProject-1.0.war
/docs/readme.txt
/docs/documentation.doc
精彩评论