Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a property file which is generated by my ant script itself during execution. And I want to access the value of properties from this generated property file.

For e.g.,

Generated Property File:

first.prop=abcd
second.prop=pqrs

and in script, I am trying to access it like this,

I am having a property name (that I want to access and is in generated property file) from some other property. That property is name.prop. so,

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

gives

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

as output respectively. What can be the solution over this?

like image 812
toshish Avatar asked Apr 12 '12 07:04

toshish


People also ask

How do I set in addition properties in ant?

In addition properties can be defined via command line arguments or similar mechanisms from outside of Ant. Normally property values can not be changed: once a property is set, most tasks will not allow its value to be modified.

How to load properties defined in XML in Apache Ant?

Since Apache Ant 1.8.0, it is possible to load properties defined in XML according to Sun DTD, when running on Java 5+. For this the name of the file, resource or url has to end with .xml. the name of the property to set. the value of the property. Sets the property to the absolute filename of the given file.

What are the built-in properties of ant?

In addition, Ant has some built-in properties: the absolute path of the project's basedir (as set with the basedir attribute of <project> ). the absolute path of the buildfile. the name of the project that is currently executing; it is set in the name attribute of <project>.

How do I use an ant reference as a property?

Any Ant type item which has been declared with a reference can also be used as a property by using the ${ant.refid:} operation, with the name of the reference listed after the ant.refid: text. The difference between this operation and ${toString:} is that ${ant.refid:} will expand to the referenced object itself.


1 Answers

This is from the doc:

Nesting of Braces

In its default configuration Ant will not try to balance braces in property expansions, it will only consume the text up to the first closing brace when creating a property name. I.e. when expanding something like ${a${b}} it will be translated into two parts:

  • the expansion of property a${b - likely nothing useful.
  • the literal text } resulting from the second closing brace

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

So it is not available easily. Workarounds (using <script /> or <macrodef /> can be found here in the official ant faq.

like image 146
oers Avatar answered Oct 03 '22 21:10

oers