Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a variable with an @ symbol mean in an Ant build.xml?

Tags:

ant

Can anyone tell me what an @ symbol before a variable means in ant build.xml file?

<subant target="@{target}">
like image 880
MeanwhileInHell Avatar asked Mar 09 '12 14:03

MeanwhileInHell


1 Answers

There are no variables in (core) ant, but properties and attributes.
@{foo} is the syntax for accessing the value of a macrodef attribute inside a macrodef, i.e. :

<project name="tryme">
 <macrodef name="whatever">
  <attribute name="foo" default="bar"/>
   <sequential>
    <echo>foo =>  @{foo}</echo>
   </sequential>
 </macrodef>

 <!-- testing 1, foo attribute not set, will use default value -->
 <whatever/>

 <!-- testing 2,  set attribute foo to 'baz'-->
 <whatever foo="baz"/>
</project>

output :

 [echo] foo =>  bar
 [echo] foo =>  baz

See Ant manual macrodef
Whereas ${foo} is the syntax for accessing the value of a property :

<project name="demo">
 <property name="foo" value="bar"/>
 <echo>$${foo} => ${foo}</echo>
</project>

output :

[echo] ${foo} => bar

See Ant manual property

like image 60
Rebse Avatar answered Sep 28 '22 15:09

Rebse