zoukankan      html  css  js  c++  java
  • maven 打包时动态替换properties资源文件中的配置值

    pom build节点下面添加resource配置:

    [html] view plain copy
     
    1. <resources>  
    2.            <resource>  
    3.                <directory>src/main/resources/</directory>  
    4.                <filtering>true</filtering>  
    5.                <includes>  
    6.                    <include>**/*.properties</include>  
    7.                </includes>  
    8.            </resource>  
    9.            <resource>  
    10.                <directory>src/main/resources/</directory>  
    11.                <filtering>false</filtering>  
    12.                <includes>  
    13.                    <include>**/*.xml</include>  
    14.                </includes>  
    15.            </resource>  
    16.        </resources>  
    [html] view plain copy
     
    1.   

    resource的filtering属性用来表示资源文件中的占位符是否需要被替换,true为需要替换。

    上面的定义是所有的.properties文件中的EL表达式占位符都会在打包时动态替换,所有的.xml文件则不会替换占位符。

    接下来我们配置两个profile,一个是测试环境,一个是正式环境配置:

    [html] view plain copy
     
    1. <profiles>  
    2.         <profile>  
    3.             <id>dev</id>  
    4.             <properties>  
    5.                 <jest.urls>http://n2:9200,http://n4:9200</jest.urls>  
    6.             </properties>  
    7.             <activation>  
    8.                 <activeByDefault>true</activeByDefault>  
    9.             </activation>  
    10.         </profile>  
    11.   
    12.         <profile>  
    13.             <id>production</id>  
    14.             <properties>  
    15.                 <jest.urls>http://192.168.3.241:9200,http://192.168.3.242:9200</jest.urls>  
    16.             </properties>  
    17.         </profile>  
    18.     </profiles>  


    我们再在src/main/resources目录下面创建一个config.properties文件,内容如下:

    jest.urls=${jest.urls}

    然后我们执行maven打包命令:clean package -DskipTests -Pdev

    查看对应的jar包里面的config.properties文件,可以发现占位符已经被替换成了profile dev中配置的jest.urls的值。

  • 相关阅读:
    c++ 左值和右值
    C++的顶层const和底层const的理解
    TCP/IP模型中的网络层
    有关TCP/IP模型中的网络接入层
    计算机网络协议与IPv4地址
    浅析计算机网络
    海思Android开发平台如何自定义update.zip内容
    Android平台RTL蓝牙适配偶现打不开问题调试笔记
    Android的SoundPool
    Android开发之IntentService
  • 原文地址:https://www.cnblogs.com/exmyth/p/7156298.html
Copyright © 2011-2022 走看看