在项目的主pom.xml文件中引入如下代码:
<!-- 不同的打包环境 -->
<profiles>
<!-- 开发环境,默认激活 -->
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!--默认启用的是dev环境配置 -->
</activation>
</profile>
<!-- 生产环境 -->
<profile>
<id>production</id>
<properties>
<env>production</env>
</properties>
<activation>
<activeByDefault>false</activeByDefault><!--默认启用的是dev环境配置 -->
</activation>
</profile>
<!-- 测试环境 -->
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
</profiles>
在配置好的maven环境中,使用cmd命令进行打包:
这是生产环境下的包
clean package -P production
这是测试环境下的包
clean package -P test
这是开发环境下的包
clean package -P test