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