Usually we will have multiple system environments, for which there should be different configuration files, usually in Maven we pack only jars, Pom, maven-plugins, war and ear. In order to be able to package the configuration files of different environments at the same time, we select Maven-assembly-plugin to package the various environment configurations under the specified path into zip and tar.gz packages.
The folder structure is as follows:
Mave standard folders
Src/main/java ...
.
Config folder and files for different env
Conf/dev (properties and log4j XML files)
conf/local
conf/uat
conf/prod
//config assembly files for different env
Src/main/assembly/config/dev.xml
src/main/assembly /config/local.xml
src/main/assembly/config/uat.xml
src/main/assembly/config/prod.xml
Maven POM Implementation:
<properties> <!----> <assemble.directory>${basedir}/conf</assemble.directory> </ Properties> <plugin> <artifactId>maven-assembly-plugin</artifactId> &
Lt;version>2.6</version> <executions> <execution>
<id>package-config</id> <!--bound to the package lifecycle phase--> <phase>package</phase> <goals> <goal>singl
E</goal> </goals> <configuration> <descriptorSourceDirectory> <!--Description folder path--> <descriptor>${basedir}/s
Rc/main/assembly/config</descriptorsourcedirectory> </descriptors>
</configuration> </execution> </executions> </plugin>
Assembly configuration file implementation (Dev as example)
<assembly xmlns= "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi= "http://www". W3.org/2001/xmlschema-instance "xsi:schemalocation=" Http://maven.apache.org/plugins/maven-assembly-plugin/assem
bly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd "> <id>config-dev</id> <formats> <format>zip</format> <format>tar.gz</format> </formats> <includebase directory>false</includebasedirectory> <fileSets> <fileSet> <directory>
${assemble.directory}/dev</directory> <outputDirectory>/${project.version}</outputDirectory> <lineEnding>unix</lineEnding> <fileMode>0644</fileMode> <d Irectorymode>0755</directorymode> <includes> <include>**/*</include>
; </includes> </fileSet> </fileSets> </assembly>
If you need to handle a configuration file, you also need to use Maven-release-plugin to handle the contents of the folder under src/conf/, such as copying Conf to target's corresponding folder, Such assembly Diretory also have to follow the modification.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>maven-resources-plugin </artifactId> <version>2.5</version> <executions> <execution> <id>dev- config</id> <goals> <goal>copy-resources</goal> </goals> <c Onfiguration> <outputdirectory>${project.build.directory}/deploy/config-dev</outputdirectory>
; <resources> <resource> <directory>${basedir}/conf/dev</d
Irectory> <filtering>true</filtering> <includes>
<include>*.properties</include> <include>*.xml</include> </include> </resource> </resources> </co nfiguration&Gt </execution> </executions> </plugin>