Maven多环境构建
Maven支持让我们配置多套环境,每套环境中可以指定自己的maven属性,
profiles元素支持定义多套环境的配置信息,配置如下用法:
<profiles>
<!-- 开发环境使用的配置 -->
<profile>
<id>dev</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/dev?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
<jdbc2.url>jdbc:mysql://192.168.10.128:3306/dev2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc2.url>
<jdbc2.driver>com.mysql.jdbc.Driver</jdbc2.driver>
<jdbc2.username>root</jdbc2.username>
<jdbc2.password>123456</jdbc2.password>
</properties>
</profile>
<!-- 测试环境使用的配置 -->
<profile>
<id>test</id>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
</profile>
<!-- 线上环境使用的配置 -->
<profile>
<id>prod</id>
<properties>
<jdbc.url>jdbc:mysql://192.168.10.128:3306/prod?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false</jdbc.url>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.username>root</jdbc.username>
<jdbc.password>123456</jdbc.password>
</properties>
</profile>
</profiles>
另外一种多环境选择方式:
<profiles>
<!-- 开发环境使用的配置 -->
<profile>
<id>dev</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>false</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/jdbc-dev.properties</filter>
</filters>
</build>
</profile>
<!-- 测试环境使用的配置 -->
<profile>
<id>test</id>
<activation>
<!--默认激活当前配置-->
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/jdbc-test.properties</filter>
</filters>
</build>
</profile>
<!-- 线上环境使用的配置 -->
<profile>
<id>prod</id>
<build>
<filters>
<filter>src/main/resources/jdbc-prod.properties</filter>
</filters>
</build>
</profile>
</profiles>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
2019-02-02 Quartz使用一