MAVEN development, replacement support for test environment properties

Source: Internet
Author: User

1) Create the Dev,product directory below src/main/resources

Src/main/resources/dev

Src/main/resources/product

2) in each of the two paths to place the appropriate configuration file for the respective environment, such as db.properties, log4j.properties, etc.

3) Configure the POM to select the environment.

3.1) Compounding Plugin

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<configuration>

<archive>

<addMavenDescriptor>false</addMavenDescriptor>

</archive>

<webResources>

<resource>

<!--This was relative to the Pom.xml directory--

<directory>src/main/resources/${package.environment}</directory>

<targetPath>WEB-INF/classes</targetPath>

<filtering>true</filtering>

</resource>

</webResources>

<packagingExcludes>

web-inf/classes/dev/,

web-inf/classes/product/

</packagingExcludes>

</configuration>

</plugin>

3.2) configuration of the Profiles

<profiles>

<profile>

<id>product</id>

<properties>

<package.environment>product</package.environment>

</properties>

</profile>

<profile>

<id>dev</id>

<properties>

<package.environment>dev</package.environment>

</properties>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

</profile>

</profiles>

<properties>

<package.environment>dev</package.environment>

</properties>

3.3) Execute MVN clean Package-pdev to complete the application generation of the dev environment.

Note: In fact, the configuration of the development environment can be placed directly in the Java/main/resources directory, so there is no need to make any corrections at the time of development. The MAVEN command is executed to generate the package only when the other environment is being published.





MAVEN development, replacement support for test environment properties

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.