Large project team, divided into development environment, test environment, production environment, different configuration, or data source, or server, or database, etc.
The question is, how do you use MAVEN to package for different environments?
MAVEN provides the concept of profile to solve such problems by simply using variable substitution; For example, the test project directory structure is shown in the following illustration:
For example, the development environment and the production environment of the database is different, the db.properties configuration files are as follows:
#测试库
db.url=192.10.2.168
db.username=dbtest
db.password=dbtest
#正式库
#db. url=192.20.1.11
#db. Username=admin
#db. password=comfreesecurity
The test environment is opened by default; the configuration file needs to be modified manually when the production environment is packaged. Juvenxu said, manual means low efficiency, high error rate!!
MAVEN provides profile functionality to address the above issues:
1, in the Pom.xml file to define two different profiles, respectively, define the development environment and production environment of the database information:
<profiles>
<profile>
<id>kaifa</id>
<properties>
<db.url> 192.10.2.168</db.url>
<db.username>dbtest</db.username>
<db.password>dbtest </db.password>
</properties>
</profile>
<profile>
<id>shengchan </id>
<properties>
<db.url>192.20.1.11</db.url>
<db.username> admin</db.username>
<db.password>comfreesecurity</db.password>
</properties>
</profile>
</profiles>
2, the original configuration file content modified as follows:
Db.url=${db.url}
Db.username=${db.username}
Db.password=${db.password}