Can Ant properties set via properties file, resolve other properties from properties files?
For example, I can do this:
<property name="prop1" value="in_test_xml1" />
<property name="prop2" value="${prop1}" />
and prop2 becomes "in_test_xml1". That's good.
But in this case, when using an input properties file:
prop1=sample_prop
prop2=${prop1}
prop2 is not set to "sample_prop"
So resolving properties from other properties only seems to work when the property doing the resolving is in the ant file itself.
Is this expected or am i missing something?
Ant does support in-file property expansion, see the Property File section in the manual for the Property task.
The following example shows properties getting resolved:
First properties file:
$ cat props1.properties
prop1=world
prop2=hello ${prop1}
Second properties file:
$ cat props2.properties
prop3=goodbye ${prop1}
Build file:
<project default="test">
<property file="props1.properties"/>
<property file="props2.properties"/>
<property name="prop4" value="${prop3}, good luck"/>
<target name="test">
<echo message="prop1 = ${prop1}"/>
<echo message="prop2 = ${prop2}"/>
<echo message="prop3 = ${prop3}"/>
<echo message="prop4 = ${prop4}"/>
</target>
</project>
Output:
$ ant
Buildfile: build.xml
test:
[echo] prop1 = world
[echo] prop2 = hello world
[echo] prop3 = goodbye world
[echo] prop4 = goodbye world, good luck
BUILD SUCCESSFUL
Total time: 0 seconds
Is there another kind of property resolution that is not working for you?
Edit
Following your comment, I now understand that you are using the -propertyfile
command line option to specify a property file for Ant to load (rather than specifying the file in the buildfile itself, as I did above).
I did quick test with this and find that Ant 1.7.1 did not do in-file property expansion on files loaded using that command line option. But Ant 1.8.2 does.
This is Ant Bug 18732. You should be able to resolve by updating your version of Ant.
A simpler solution for this task would be the usage of Ant-contrib Tasks: Propertycopy.
From the manual:
<property name="org" value="MyOrg" />
<property name="org.MyOrg.DisplayName" value="My Organiziation" />
<propertycopy name="displayName" from="org.${org}.DisplayName" />
Sets displayName to "My Organiziation".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With