Maven Plug-in Portable-config-maven-plugin (packaged in different environments)

Source: Internet
Author: User
Tags config

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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.