当前位置: 首页 > news >正文

maven多环境配置

maven多环境配置

参考网址:

https://mp.weixin.qq.com/s/-e74bd2wW_RLx7i4YF5M2w

https://mp.weixin.qq.com/s/3p53kBHqys58QdMme6lR4A

项目地址

https://gitee.com/shao_ming314/maven-profile-dir

项目说明

该项目基于目录进行多环境配置 , 具体的配置文件在

src/resources/profiles 目录下

dev 开发环境

test 测试环境

prd 生产环境

image-20230219222131905

pom.xml说明

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.shaoming</groupId><artifactId>maven-profile-dir</artifactId><version>1.0-SNAPSHOT</version><properties><!-- 指定资源文件复制过程中采用的编码方式 --><encoding>UTF-8</encoding></properties><dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.11</version></dependency></dependencies><profiles><profile><!-- 开发环境 --><id>dev</id><properties><profiles.active>dev</profiles.active></properties><activation><activeByDefault>true</activeByDefault></activation></profile><profile><!-- 测试环境 --><id>test</id><properties><profiles.active>test</profiles.active></properties></profile><profile><!-- 生产环境 --><id>prd</id><properties><profiles.active>prd</profiles.active></properties></profile></profiles><build><finalName>maven-profile-dir</finalName><!-- filter 具体基本没用 -->
<!--        <filters>-->
<!--            <filter>src/main/resources/profiles/${profiles.active}/jdbc.properties</filter>-->
<!--        </filters>--><resources><resource><directory>src/main/resources</directory><!-- 这个filter必须要设为true, 把所有文件都过滤掉,然后下面再手动include,一个一个文件夹自己添加 --><filtering>true</filtering><includes><include>*.xml</include><include>my.properties</include></includes><excludes><exclude>log4j.properties</exclude><exclude>jdbc.properties</exclude></excludes></resource><resource><!-- 这里会直接把${profiles.active}对应文件夹下的内容打包到classpath下 --><directory>src/main/resources/profiles/${profiles.active}</directory></resource></resources><testResources><testResource><directory>src/test/resources</directory><!-- 这个filter必须要设为true, 把所有文件都过滤掉,然后下面再手动include,一个一个文件夹自己添加 --><filtering>true</filtering><includes><include>*.xml</include><include>my.properties</include></includes><excludes><exclude>log4j.properties</exclude><exclude>jdbc.properties</exclude></excludes></testResource><testResource><!-- 这里会直接把${profiles.active}对应文件夹下的内容打包到classpath下 --><directory>src/test/resources/profiles/${profiles.active}</directory></testResource></testResources></build>
</project>

配置文件说明

源码和测试中 , jdbc.properties 和 log4j.properties 是基于多环境配置的

其它文件都使用 src/resources 目录的文件

源码

  • jdbc.properties

  • log4j.properties

测试

  • jdbc.properties

  • log4j.properties

image-20230219222550330

http://www.lryc.cn/news/13151.html

相关文章:

  • 设计模式之中介模式与解释器模式详解和应用
  • 2023年全国最新交安安全员精选真题及答案1
  • chrome插件开发备忘录
  • 实例1:控制树莓派板载LED灯闪烁
  • 华为OD机试题 - 最大排列(JavaScript)
  • 手动创建 vue2 ssr 开发环境
  • RHCE-操作系统刻录工具
  • PHP面向对象01:面向对象基础
  • 《爆肝整理》保姆级系列教程python接口自动化(十八)--重定向(Location)(详解)
  • MySQL的索引、视图
  • 【JavaWeb】网络层协议——IP协议
  • 【Python学习笔记】41.Python3 多线程
  • Windows 版本ffmpeg编译概述
  • NETCore下CI/CD之自动化测试 (详解篇)
  • Hoeffding不等式剪枝方法
  • 【算法】数组中的重复数字问题
  • 数值方法笔记2:解决非线性方程
  • 基于SpringBoot的在线文档管理系统
  • 软件体系结构(期末复习)
  • [vue3] pinia的基本使用
  • 进程和线程详解
  • 《刀锋》读书笔记
  • nginx中的ngx_modules
  • 设计模式之访问者模式
  • Go项目(三)
  • CTK学习:(一)编译CTK
  • 15种NLP数据增强方法总结与对比
  • Python每日一练(20230219)
  • vTESTstudio - VT System CAPL Functions - VT7001
  • 「可信计算」论文初步解读