maven中properties加载顺序

  1. <build><filters></filters></build>中的配置
  2. pom.xml中的<properties>
  3. mvn -Dproperty=value中定义的property

相同的key的property以最后一个文件中配置为准

不同环境不同配置文件

<profiles>
<profile>
<id>develop</id>
<activation>
<!--设置默认值 -->
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<!--将develop文件夹下都复制到resource中 -->
<directory>profiles/develop</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>release</id>
<build>
<resources>
<resource>
<directory>profiles/release</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</profile>
<profile>

不同环境相同配置文件,不同值

  • 方法一:通过配置文件
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>sit</id>
<properties>
<env>sit</env>
</properties>
</profile>
</profiles> <build>
<!--设置需要替换值的文件 -->
<filters>
<filter>
src/main/filter/filter-${env}.properties
</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--对这里的文件进行解析 -->
<filtering>true</filtering>
</resource>
</resources>
</build>
  • 方法二
<profiles>
<profile>
<id>dev</id>
<properties>
<!--不同环境不同参数在此配置 -->
<env>dev</env>
<remoteconfig>true</remoteconfig>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>sit</id>
<properties>
<remoteconfig>false</remoteconfig>
<env>sit</env>
</properties>
</profile>
</profiles> <build>
<!--要解析一定要设filtering为true -->
<resources>
<resource>
<directory>src/main/resources</directory>
<!--对这里的文件进行解析 -->
<filtering>true</filtering>
</resource>
</resources>
</build>

resources

与是用来圈定和排除某一文件目录下的文件是否是工程资源的。如果与划定的范围存在冲突时,以划定的范围为准。

 	<resources>
<!-- 需要解析jdbc和mail两个文件 -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>jdbc.properties</include>
<include>mail.properties</include>
</includes>
</resource>
<!-- 需要不需要解析jdbc和mail两个文件 -->
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>jdbc.properties</exclude>
<exclude>mail.properties</exclude>
</excludes>
</resource>
</resources>

其中第一段<resource>配置声明:在src/main/resources目录下,仅jdbc.propertiesmail.properties两个文件是资源文件,然后,这两个文件需要被过滤。而第二段<resource>配置声明:同样在src/main/resources目录下,除jdbc.propertiesmail.properties两个文件外的其他文件也是资源文件,但是它们不会被过滤。

引用: 用 maven filter管理不同环境的配置文件关于Maven resource配制中include与exclude的关系

maven多环境参数配置的更多相关文章

  1. 详解Maven用户的配置settings.xml

    Maven用户设置 作者其他技术文章 1)Oracle性能优化之查询语句通用原则 2)Redis常用命令 3) SpringCloud入门之常用的配置文件 application.yml和 boots ...

  2. Maven 本地资源库配置

    Maven 本地资源库配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.操作系统环境 1>.查看操作系统环境(总共3台虚拟机) 2>.关闭防火墙并禁用开机自启动( ...

  3. [Java] Maven 安装和配置

    1. 下载 Maven 在百度输入 Maven 搜索 ,找到它的官网(http://maven.apache.org/),点击进入下载页面. 下载页面地址: http://maven.apache.o ...

  4. maven安装和配置

    一.下载maven maven下载页 里面有一些版本区别,binary比较小,适合直接在项目中使用,source带了源代码,windows系统下载zip后缀的 apache-maven-3.3.9-b ...

  5. maven - 安装与配置

    最近在了解maven的相关东西,在网上查了一些资料,现在简单整理一下. 一.maven 安装 1.先检查JDK ,Maven是一个java工具,所以请确保jdk环境已经正确安装在你的机器上. 2.点击 ...

  6. 【maven】之配置开发,测试,正式环境pom.xml文件

    在进行web程序开发,如果项目组没有使用自动化发布工具(jenkins + maven + svn + tomcat ),我们一般会使用maven的热部署来完成发布,在部署的过程中我们开发,测试,生产 ...

  7. Maven安装与配置

    下载: 1.从官网http://maven.apache.org中下载,下载下来的是一个压缩包,解压即可.因为Maven本身也是用Java实现的.2.Maven的目录结构   /bin; maven的 ...

  8. maven 环境的配置 JAVA_HOME not found in your envirnment

    maven 的环境配置在配置maven前 先做好java的环境配置现在假定java已经配置好了.在环境变量中添加;maven的解压路径\bin 例如:D:\soft\java\apache-maven ...

  9. MyEclipse下Maven的安装配置

    Maven常用命令: •mvn archetype:generate :创建 Maven 项目 •mvn compile :编译源代码 •mvn test-compile :编译测试代码 •mvn t ...

随机推荐

  1. 激活prompt

    1.下载SQLPrompt 2. 断网, 打开注册机,拷贝验证码 2. 点击activate, 拷贝代码

  2. spring rabbitmq集成

    pom.xml加 <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-clien ...

  3. Laravel-nestedset that base left and right values tree package

    This is a Laravel 4-5 package for working with trees in relational databases. Laravel 5.5, 5.6, 5.7, ...

  4. 【ZooKeeper】ZooKeeper安装及简单操作

    ZooKeeper介绍 ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件.它是一个为分布式应用提供一 ...

  5. codeforces 508B

    B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. php循环

    while 例子: /* example 1 */ $a = 0; while (true) { $a++; echo $a.'<br>'; if($a >= 10){ break; ...

  7. Python开发——5.函数

    一.函数的定义 def test(x) "The Function definitions" x += return x def:定义函数的关键字 test:函数名 ():定义形参 ...

  8. 下划线字符串camel

    const camel = (str) => { let slices = str.split('_'); let result = []; for(let i = 1, len = slice ...

  9. elasticsearch 安装,以及遇到的问题总结

    系统.软件环境: Centos 6.5 elasticsearch 6.1.1 elasticsearch 安装的话是很简单的,但是安装完成启动的时候报错,下面我就一一的来描述错误,并提供相应的解决方 ...

  10. jvm虚拟机--垃圾回收子系统

    转载自cyc2018的github:https://github.com/CyC2018/Interview-Notebook/blob/master/notes/Java%20%E8%99%9A%E ...