Java Study Notes 8-Multi-Environment packaging with maven profile

Source: Internet
Author: User

Project development requires multiple environments, which are generally development, testing, pre-release, and formal. maven can be used to package and deploy projects in different environments. The command is: in mvn package-P dev, "dev" is the environment variable id, which can be defined by myself. The name I defined is dev, qa, pre, prod, which is specific in pom. the configuration in xml is as follows: [html] <? Xml version = "1.0" encoding = "UTF-8"?> <Project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> ...... <profiles> <profile> <id> dev </id> <properties> <env> dev </env> </properties> <activation> <activeByDefault> true </activeByDefault> </activation> </profile> <id> qa </id> <properties> <env> qa </env> </properties> </profile> <profile> <id> pre </id> <properties> <env> pre </env> </properties> </profile> <id> prod </id> <properties> <env> prod </env> </properties> </profile> </profiles> ...... <build> <filters> <filter> config/$ {env }. properties </filter> </filters> <resources> <resource> <directory> src/main/resources </directory> <filtering> true </filtering> </resource> www.2cto.com </resources> ...... </build> </project> 1. profiles defines the address of the variable configuration file in id2.filters of each environment. The environment variable in the address is the value defined in profile above 3. resources defines the directories under which files will be replaced by the variables defined in the configuration file. Generally, we will place the project configuration file under src/main/resources, such as db, bean, the variables used in the package will be replaced with fixed values according to the variable configuration in the filter.

Related Article

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.