maven环境隔离

  1. pom <build>节点下增加节点
<resources>
	<resource>
		<directory>
			src/main/resources.${deploy.type}
		</directory>
		<excludes>
			<exclude>
				*.jsp
			</exclude>
		</excludes>
	</resource>
	<resource>
		<directory>
			src/main/resources
		</directory>
	</resource>
</resources>
  1. pom <project>节点下增加节点
<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>
  1. resources文件夹的同级目录下创建以下文件夹
  • resources.dev
  • resources.test
  • resources.prod
  1. resources目录下需做环境隔离的配置文件分别拷贝到上一步创建的文件夹下, 并修改相应配置, 将公共的配置文件保留在resources目录

  2. maven打包编译命令
    mvn clean package -DskipTests -Pdev

搞定

posted @ 2019-05-23 21:55  wangzaiplus  阅读(140)  评论(0编辑  收藏