Location: JWare Software » AntXtras » Documents » How Tos » Stop ${} Evaluation
Stop ${} Evaluation
Q: How do I stop Ant from evaluating ${...}?
At some point you will find it necessary to use the standard ‘${…}’ pattern in a string and you want to block Ant from interpreting this string as if it contained a property reference. Such a situation might occur for example, if you’re creating a properties file that contains values with property references that an application will interpolate when it loads the file.
Because AntXtras replaces the default Ant property evaluator in order to support recursive property evaluation, we have included support for the standard ‘$${…}’ hack feature that both blocks evaluation of the property reference pattern and collapses the ‘$${…}’ into just ‘${…}’ in the resulting string.
So an instruction that uses a standard Ant task like:
<echo message="$${ant.version} = ‘${ant.version}’"/>
Would generate something like:
[echo] ${ant.version} = ‘Apache Ant version 1.6.5 compiled on June 2 2005’
AntXtras-based components are very aggressive in trying to resolve property references. An AntXtras component’s attribute and text can be evaluated at least twice: first when Ant parses the component’s parent container (like a <target> or <macrodef> instance) and then when AntXtras is about to actually use the value. What this means to you, is that you might need to include an extra ‘$’ for every “ignore-this” instruction you want to give an AntXtras component. So instead of ‘$${…}’ you might need ‘$$${…}’. (Note that this statement applies to all AntXtras-based components including other independent packages like Log4Ant, SAMS, and AntUnit.)
From the previous example, if we used an AntXtras-based component, we might write this instead:
<emit message="$$${ant.version} = ‘${ant.version}’" from="General"/>