Search code examples
ant

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


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

<subant target="@{target}">

Solution

  • 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