maven多环境配置(多环境配置,开发环境、测试环境与开发环境分开打包)

mac2022-06-30  60

1、将公共的配置文件放在resources里面,开发环境、生产环境、测试环境分别放在resources.dev、resources.test、resources.prod

2、在pom.xml设置

<build> <resources> <resource> <!--把相对应的独特资源(dev,test,prod这三种的一种)声明,排除jsp文件--> <directory>src/main/resources.${deploy.type}</directory> <excludes> <exclude>*.jsp</exclude> </excludes> </resource> <resource> <!--声明公共资源--> <directory>src/main/resources</directory> </resource> </resources> </build> <!--分别设置开发,测试,生产环境--> <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、使用maven进行多环境打包

-Dmaven.test.skip=true 为测试打包和测试编译,-P后面接的是所需要打包环境的id,如dev开发环境,test测试环境,如果不写-P,默认为dev即开发环境

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

4、当开发的时候,联合本地tomcat使用方法

1、intellij idea 如图所示,选上对应的环境,然后运行tomcat即可2、eclipse 右键项目配置,然后选上maven,输入你需要的环境id,如dev

转载于:https://www.cnblogs.com/zhongjc/p/8618113.html

相关资源:maven多环境配置打包
最新回复(0)