zoukankan      html  css  js  c++  java
  • maven 编译替换占位符

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

    <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环境的配置

  • 相关阅读:
    复制带中文的公式贴到通达信公式中显示乱码解决方案
    命令指定线程个数
    随机姓名
    将二维list某列组成新的list
    jenkins配置小结
    jmeter5.0 while controller使用总结
    centos7 桌面化配置
    django study1 数据库
    centos7 安装firefox
    python之self
  • 原文地址:https://www.cnblogs.com/Leechg/p/10280911.html
Copyright © 2011-2022 走看看