1.pom.xml文件中在build标签中加入:
<build>
<resources>
<resource>
<directory>src/main/resources.${deploy.type}</directory>
<excludes>
<exclude>*.jsp</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
2.继续在标签中加入:
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<deploy.type>dev</deploy.type>
</properties>
</profile>
<profile>
<id>beta</id>
<properties>
<deploy.type>beta</deploy.type>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<deploy.type>prod</deploy.type>
</properties>
</profile>
</profiles>
本地开发环境(Local)
开发环境(Dev)
测试环境(Beta)
线上环境(Prod)
这里没有加本地的开发环境
<activeByDefault>true</activeByDefault>
这个配置默认的是使用这个开发环境,例如上面的就是默认使用开发环境的配置
3.然后新建对应的文件夹,并把要隔离的文件分开,公共的留下:
4.IDEA中设置默认环境:
这里可以多选,但选择一个就可以,还有注意点就是勾号有虚的半选和实心的实选,要保证单选的实心,多选容易造成环境的错乱
5.编译打包命令:
maven clean package -Dmaven.test.skip=true -P${环境标识}
例如 maven clean package -Dmaven.test.skip=true -Pdev