首先开启资源配置的插件,由此插件替换占位符

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<useDefaultDelimiters>false</useDefaultDelimiters>
<delimiters>
<delimiter>${*}</delimiter>
</delimiters>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

然后配置字典的目录,占位符的值从这个文件中取得

<build>
<filters>
<filter>src/main/resources/config/${env}.properties</filter>
</filters>
...

配置要被替换的文件目录,该目录下的文件中的占位符会被替换掉

<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources> 。。。

配置profiles  在profile中定义env参数用来指定不同profile下使用的字典文件

<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>server54</id>
<properties>
<env>server54</env>
</properties>
</profile>
</profiles>

在 src/main/resources/config/  文件夹下创建爱你对应的 ${env}.properties就可以了

logging.path=/usr/local/RestData/log/
etl.allowRunTask=false

使用命令行打包项目,发现application.propties中的占位符被替换了

maven clean  package -P server54

在开发环境下默认的是dev配置,右键项目 maven--update 就可以使用dev环境的配置

maven 编译替换占位符的更多相关文章

  1. Roslyn 使用 Target 替换占位符方式生成 nuget 打包

    本文告诉大家如何编写在编译过程修改打包文件 在项目文件的相同文件夹可以放一个 nuspec 用来告诉 VisualStudio 如何打包 现在尝试创建一个项目 NearjerbetearDeeyito ...

  2. String替换占位符

    /** * 依次替换占位符 * 例如: 姓名:{s},电话:{s},邮箱:{s} --> 姓名:小张,电话:18800000001,邮箱:abc@123.com * pattern = &quo ...

  3. maven如何过滤占位符

    今天遇到一个问题,就是properties文件中赋值用的这种形式${xxx},真正的值是配置在pom的profile中,但是未生效. 后来找到原因,原来是pom中少了一段代码: <build&g ...

  4. spring中PropertyPlaceholderHelper替换占位符的值

    1.Properties中的值替换¥{}或者#{}占位符 String text = "foo=${foo},bar=${bar}"; Properties props = new ...

  5. Spring Boot使用Maven打包替换资源文件占位符

    在Spring Boot开发中,通过Maven构建项目依赖是一件比较舒心的事,可以为我们省去处理冲突等大部分问题,将更多的精力用于业务功能上.近期在项目中,由于项目集成了其他外部系统资源文件,需要根据 ...

  6. spring源码解析(一)---占位符解析替换

    一.结构类图 ①.PropertyResolver : Environment的顶层接口,主要提供属性检索和解析带占位符的文本.bean.xml配置中的所有占位符例如${}都由它解析 ②.Config ...

  7. maven占位符

    maven占位符默认是${} 也可以自己指定. pom.xml配置如下: <plugin> <groupId>org.apache.maven.plugins</grou ...

  8. 【Spring源码分析】.properties文件读取及占位符${...}替换源码解析

    前言 我们在开发中常遇到一种场景,Bean里面有一些参数是比较固定的,这种时候通常会采用配置的方式,将这些参数配置在.properties文件中,然后在Bean实例化的时候通过Spring将这些.pr ...

  9. 【占位符替换】替换String中的占位符标志位{placeholder}

    概述 占位符替换, 占位符表示为:{placeholder}; 示例:替换如下{xxx}占位符中的内容 "名字:{name},年龄:{age},学校:{school}" 提供了两种 ...

随机推荐

  1. [LeetCode]Letter Combinations of a Phone Number题解

    Letter Combinations of a Phone Number: Given a digit string, return all possible letter combinations ...

  2. 《JavaWeb从入门到改行》注册时向指定邮箱发送邮件激活

    javaMail API javaMail是SUN公司提供的针对邮件的API . 两个jar包  mail.jar 和 activation.jar java mail中主要类:javax.mail. ...

  3. Effective C++ .47 traits与模板特化

    #include <iostream> #include <cstdlib> #include <string> using namespace std; temp ...

  4. HTML新手推荐

    对于前端的学习要先了解一下浏览器和html的发展史其次看看这篇文章:https://kb.cnblogs.com/page/129756/#chapter1我读到这句话时候感觉到了科技这个东西有很多时 ...

  5. USACO08MAR土地购买 与 APIO2010特别行动队

    两道斜率优化DP: 土地购买 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选择并购一组土地,并购的价格为这些土地中最大的长 乘以最大的 ...

  6. 普通平衡树Tyvj1728、luogu P3369 (splay)

    存个模板,这次是splay的: 题目见这个题解: <--(鼠标移到这儿) 代码如下: #include<cstdio> #define INF 2147483647 using na ...

  7. linq返回的IEnumerable<T>泛型不能被列举计算大于1次

    在分页获取Take后面加ToList()方法就能得到正确结果,为什么?

  8. Leetcode算法比赛----Longest Absolute File Path

    问题描述 Suppose we abstract our file system by a string in the following manner: The string "dir\n ...

  9. Appium+java移动端项目测试问题整理

    一.每次打开APP都要重新安装.充值账号密码 解决:打开appium,设备,Use Browser  ,勾选“No Reset”   二.一个页面包含相同文字,打开页面路径错误 问题描述:APP处于[ ...

  10. 反射报错java.lang.IllegalArgumentException: wrong number of arguments

    class Person{ private String name ; private String sex ; public Person(){ System.out.println("c ...