Maven实现多环境打包
Maven实现多环境打包
撸起袖子便是干:
目录如下:
不同目录自己写入文件及内容加以区分。
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yfc.test.package</groupId>
<artifactId>test.package</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>prod</id>
<properties>
<package.environment>prod</package.environment>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>qa</id>
<properties>
<package.environment>qa</package.environment>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 资源根目录排除各环境的配置,使用单独的资源目录来指定 -->
<excludes>
<exclude>qa/*</exclude>
<exclude>prod/*</exclude>
<exclude>dev/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${package.environment}</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
测试:
mvn clean package 或者 mvn clean package -Pdev 即构建出开发环境需要的war包
mvn clean package -Pqa 即构建出测试环境需要的war包
mvn clean package -Pprod 即构建出生产环境需要的war包
注:如果在eclipse中执行,请不要加命令mvn开头: