MAVEN Packaging configuration file

Source: Internet
Author: User

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&gt
            ; </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&gt 
              ; <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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.