Preamble:
maven 命令:clean package -Dmaven.test.skip=true -P product
1. The command is very simple: clear the class file, package and build, skip the test , pay attention to the last -P product, -P maven will activate the id under the <profiles> tag of the pom.xml configuration under the project is product
- <profiles>
- <profile>
- <id>product</id>
- <properties>
- <env>product</env>
- </properties>
- </profile>
- </profiles>
2. Use the ${env} defined in the placeholder configuration above for resource filtering
- < bulid > <!--Specify resource directory configuration whether to enable resource filtering (that is, whether to enable placeholder replacement) -->
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>logback.xml</include>
- </includes>
- </resource>
- </rwsources>
- <!-- variable source -->
- <filters>
- <filter>src/main/resources/log-profile-${env}.properties</filter>
- </filters>
- </build>
3. Activate the profile through maven's setting settings (the second global activation method can be ignored. If you use <env>, this value will be overwritten)
- <activeProfiles>
- <activeProfile>product</activeProfile>
- </activeProfiles>
Summary:
1. The -P parameter cooperates with the resource filtering Filter, and finally uses the src/main/resources/log-profile-product.properties file
2. This configuration file provides the corresponding value for the logback.xml file that can use placeholders
3. Activation profile and spring profile are a bit like-minded. This configuration activation of maven can also be used in many aspects, such as snapshot repository (version) for development environment and release repository for production.