【问题标题】:Creating an ANT macro to combine two properties file创建一个 ANT 宏来组合两个属性文件
【发布时间】:2015-09-08 17:12:55
【问题描述】:

假设我有两个包含键值对的属性文件(比如 a.properties 和 b.properties)。如何编写 ANT 任务来创建一个新的属性文件(比如 c.properties),其中包含这两个文件(a 和 b)的键值对。请帮忙。

【问题讨论】:

    标签: ant properties-file build.xml


    【解决方案1】:

    你可以使用 concat

    <?xml version="1.0" encoding="utf-8"?>
    <project name="Build SmartLisaNightly" default="info">
    
    <target name="readproperties">
        <concat destfile="c.properties" >
            <fileset file="a.properties" />
            <fileset file="b.properties" />
        </concat>
        <property file="c.properties" />
    </target>
    
    <target name="info" depends="readproperties">
    <echo>
    p1 ${p1}
    p2 ${p2}
        </echo>
        </target>
    </project>
    

    另见https://ant.apache.org/manual/Tasks/concat.html

    我的测试表明,如果 a.properties 和 b.properties 包含相同的属性,则使用 b.properties 中的定义。我不知道这是否被记录为这样的功能。

    a.properties

    p1=from_a
    p2=from_a
    

    b.properties

    p2=from_b
    

    蚂蚁输出

    readproperties:
    
    info:
         [echo]
         [echo] p1 from_a
         [echo] p2 from_b
    

    【讨论】:

    • 我无法让它工作。对我来说,它只是将 b.properties 的内容放在 a.properties 的内容之后。
    猜你喜欢
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 1970-01-01
    相关资源
    最近更新 更多