不同环境的如何配置不同的变量
第一种
pom.xml(默认)
pom_test.xml
pom_prod.xml
pom_dev.xml# 生产环境
mvn clean package -f pom_prod.xml
# 测试环境
mvn clean package -f pom_test.xml
# 开发环境
mvn clean package -f pom_dev.xml第二种
第三种
Last updated
pom.xml(默认)
pom_test.xml
pom_prod.xml
pom_dev.xml# 生产环境
mvn clean package -f pom_prod.xml
# 测试环境
mvn clean package -f pom_test.xml
# 开发环境
mvn clean package -f pom_dev.xmlLast updated
├──profiles
| |
| |——test
│ │ └──my.properties
│ ├──prod
│ │ └──my.properties
│ └──dev
│ └──my.properties<profiles>
<profile>
<!--默认使用该配置-->
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<package.environment>test</package.environment>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<package.environment>prod</package.environment>
</properties>
</profile>
</profiles><plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<resourceEncoding>utf-8</resourceEncoding>
<webappDirectory>${project.build.directory}/${project.artifactId}</webappDirectory>
<warName>${project.artifactId}</warName>
<webResources>
<!--这里的文件会copy到targetPath下,覆盖掉执行resource:resource目标时复制文件-->
<resouce>
<directory>${project.basedir}profiles/${package.environment}</directory>
<targetPath>WEB-INF/classes</targetPath>
<!-- 替换占位符 -->
<filtering>true</filtering>
</resouce>
</webResources>
</configuration>
</plugin># 开发环境
mvn clean package -Pprod
# 测试环境
mvn clean package -Ptest
# 开发环境
mvn clean package -Pdev<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- jdbc -->
<jdbc_username>xxxx</jdbc_username>
<jdbc_password>yyyyyy</jdbc_password>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<!-- jdbc -->
<jdbc_username>xxxx</jdbc_username>
<jdbc_password>yyyyyy</jdbc_password>
<dbcp_max_active>10</dbcp_max_active>
<dbcp_max_idle>5</dbcp_max_idle>
<dbcp_min_idle>2</dbcp_min_idle>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<jdbc_username>xxxx</jdbc_username>
<jdbc_password>yyyyyy</jdbc_password>
<dbcp_max_active>10</dbcp_max_active>
<dbcp_max_idle>5</dbcp_max_idle>
<dbcp_min_idle>2</dbcp_min_idle>
</properties>
</profile>
</profiles><resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources># 开发环境
mvn clean package -Pprod
# 测试环境
mvn clean package -Ptest
# 开发环境
mvn clean package -Pdev