Is it possible to specify the value of a property as a property in ant?

I have a properties file that is created at runtime of my ant script. And I want to access the property value from this generated property file.

For example,

Generated Property File:

first.prop=abcd second.prop=pqrs 

and in the script, I try to access it like this,

I have a property name (which I want to get in the file of the generated property) from another property. This is the name.prop property. so,

 <echo message="${name.prop}"/> <echo message="${${name.prop}}"/> 

gives

 first.prop ${${name.prop}} 

as a conclusion, respectively. What could be the solution to this?

+7
source share
2 answers

This is from the doc :

Insert braces

In its default configuration, Ant will not try to balance braces in property extensions; it will consume only text until the first closing the bracket when creating the property name. That is, when expanding, something like $ {a $ {b}} will be translated into two parts:

  • expansion of the property a $ {b is hardly useful.
  • literal text} resulting from the second trailing parenthesis

This means that you cannot easily use the properties whose names are given by the properties, but there are some workarounds for older versions from Ant. With Ant 1.8.0 and Antlib props, you can configure Ant to use NestedPropertyExpander there if you need such a feature.

So this is not possible. Workarounds (using <script /> or <macrodef /> can be found here in the official Ant faq .

+8
source
 I tried this, to get similar values<br/> prop.properties contains: a=val1 b=val2 c=val3 batch.props=a,b,c <for list="${batch.props}" param="prop"> <sequential> <echo>@{prop} is ${ batch.@ {prop}}</echo> </sequential> </for> Got Ans as below: a is val1 b is val2 c is val3 Enjoy! 
0
source

All Articles