Creating an ANT macro to combine two properties file

809 views Asked by At

Suppose that I have two properties file (say a.properties and b.properties) which contains key value pair. How to write ANT task to create a new properties file (say c.properties) which contains the key value pair of both these files(a and b). Please help.

1

There are 1 answers

1
carl verbiest On BEST ANSWER

You can use 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>

see also https://ant.apache.org/manual/Tasks/concat.html

My tests show that if a.properties and b.properties contain the same properties the definition in b.properties is used. I don't know if this is documented to function like that.

a.properties

p1=from_a
p2=from_a

b.properties

p2=from_b

ant output

readproperties:

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