原文出处:
https://faceghost.com/article/623591
先介绍分离后的命令:
启动命令:
tomcat7:run -Pdev //开发环境 tomcat7:run -Ppro //生产环境
打war包命令
install -Pdev //开发环境 install -Ppro //生产环境
项目新增dev,pro目录
在 /src/main/resources 新增文件夹 “dev” ,“pro”
如图所示:
其中 dev 存放开发环境配置
其中 pro 存放生产环境配置
打开pom.xml ,修改参考如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> ... <dependencies> ... </dependencies> <!-- 配置文件 --> <profiles> <profile> <!--开发环境 --> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> </profile> <profile> <!--生产环境 --> <id>pro</id> <properties> <profiles.active>pro</profiles.active> </properties> </profile> </profiles> <build> <!--资源根目录排除各环境的配置,使用单独的资源目录来指定 --> <resources> <resource> <directory>src/main/resource</directory> <excludes> <exclude>/dev/*</exclude> <exclude>/pro/*</exclude> </excludes> </resource> <resource> <directory>src/main/resources/${profiles.active}</directory> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> <warName>xxx</warName> <packagingExcludes> WEB-INF/classes/dev/**, WEB-INF/classes/pro/**</packagingExcludes> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/xxx</path> <contextFile>\${tomcatContextXml}</contextFile> <protocol>org.apache.coyote.http11.Http11NioProtocol</protocol> <uriEncoding>utf-8</uriEncoding> </configuration> </plugin> </plugins> </build> </project>
转载请注明:
原出处:见鬼网
原作者:xingfu2017