Maven Profile multi-environment build
Configuration file directory structure
|-- resources
| |-- dev
| |-- production
| | - qa
Edit pom.xml
<build> <resources> <resource> <directory>src/main/resources</directory> <!-- The resource root directory excludes the configuration of each environment and uses a separate resource directory to specify, In this way, public files (that is, files in the resources directory other than these three directories) do not need to be specified repeatedly --> <excludes> <exclude>qa/*</exclude> <exclude>prod*/*</exclude> <exclude>dev*/*</exclude> </excludes> </resource> <resource> <directory>src/main/resources/${profiles.active}</directory> </resource> </resources> </build> <profiles> <profile> <id>product</id> <properties> <package.environment>product</package.environment> </properties> </profile> <profile> <id>dev</id> <properties> <package.environment>dev</package.environment> </properties> </profile> <profile> <id>qa</id> <properties> <package.environment>qa</package.environment> </properties> </profile> </profiles>
You can specify the default startup profile, and add it to the profile node (behind properties).
<activation>
<activeByDefault>true</activeByDefault>
</activation>
In IntelliJ IDEA, check the specified profile in the Maven Projects on the right, for example: production
Then specify the lifecycle, such as clean, compile, etc. After execution, the configuration files in the production directory will be output to the compiled classes directory.
mvn clean package -Pproduction is to build the war package required for the production environment
mvn tomcat:redeploy -Pqa is released to the test environment