maven profile: Step by Step

来源:互联网 发布:mac spss 24破解dmg 编辑:程序博客网 时间:2024/06/15 19:10
During the lifecircle of development, we need some different config profiles for different enviroments. Such as the dev, bts, prod enviroments. Here we will see how to create maven profile forvariety enviroments.

Step 1: config theprofile of POM.xml
Tips: we define 3 enviroments: dev, bts, prod. The dev is default to active(config by activeByDefault), if profiles are not specified, use the default profile config.
profiles.active means the config file directory for the active profile
Step 2: The project directory
Tips: The config files are different from different environments. We should put this files toresouces directory of maven's project(src/main/resources) . The common resources file put to the src/main/resources.
The config file (du.properties,dataservices) of dev is put to src/main/resources/dev
The config file (du.properties,dataservices) of btss put to src/main/resources/bts

Step 3: Thebuild config in pom.xml
Tips: First-node ofresource need to exclude all of different config file for diffrent environments. The config for different environments is defined in second-node ofresource.
e.g. If the current active profile isdev, then the ${profileds.active} will be interpolated todev. Then the active direcotry issrc/main/resources/dev.

Step 4: build project using profile
(1) in Intellij Idea, u can see checked the profile box inmaven-profile-view

(2) u can also use the compile line such as: mvn intall -P dev