maven multi environment configuration (multi environment configuration, development environment, test environment and development environment are packaged separately)

Keywords: Java JSP Maven Tomcat xml

1. Put the public configuration file in resources, the development environment, production environment and test environment in resources.dev, resources.test and resources.prod respectively

2. Set in pom.xml

<build>
        <resources>
            <resource>
                <!--Put the corresponding unique resources(dev,test,prod One of the three)Declaration, exclusion jsp file-->
                <directory>src/main/resources.${deploy.type}</directory>
                <excludes>
                    <exclude>*.jsp</exclude>
                </excludes>
            </resource>
            <resource>
                <!--Declare public resources-->
                <directory>src/main/resources</directory>
            </resource>
        </resources>
    </build>

    <!--Set up development, test and production environment respectively-->
    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <deploy.type>dev</deploy.type>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <deploy.type>test</deploy.type>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <deploy.type>prod</deploy.type>
            </properties>
        </profile>
    </profiles>

3. Using maven for multi environment packaging

-Dmaven.test.skip=true for test packaging and test compilation, - P is followed by the id of the required packaging environment, such as dev development environment and test test environment. If - P is not written, dev is the development environment by default

mvn clean package -Dmaven.test.skip=true -Ptest

4. When developing, combine local tomcat usage

  • 1,intellij idea
    As shown in the figure, select the corresponding environment and run tomcat
  • 2,eclipse
    Right click the project configuration, select maven, and enter the environment id you need, such as dev

Posted by ambivalent on Fri, 03 Apr 2020 07:13:34 -0700