maven打包命令-P和-D的用法

-D

我们工程里一般有开发环境(dev)、测试环境(test)、现场环境(prod),如何使用maven命令来指定打哪个环境的war包呢?
首先,-D是针对配置属性的。pom文件里默认是dev环境,使用命令:mvn package -Denv=prod 就可以直接打成现场环境的war包了。

<properties>
  <spring.version>4.3.3.RELEASE</spring.version>
  <env>dev</env>
</properties>

-P

配置多个profile,然后输入命令:mvn package -Ptest1就可以指定加载test1下的资源。

<profiles>
        <profile>
            <id>test1</id>
            <build>
                <resources>
                    <resource>
                        <directory>profiles/test1</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                    </resource>
                </resources>
            </build>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test2</id>
            <build>
                <resources>
                    <resource>
                        <directory>profiles/test2</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                    </resource>
                </resources>
            </build>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test3</id>
            <build>
                <resources>
                    <resource>
                        <directory>profiles/test3</directory>
                        <includes>
                            <include>**/*.*</include>
                        </includes>
                    </resource>
                </resources>
            </build>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
    </profiles>

你可能感兴趣的:(maven)