2012-03-09 82 views

回答

14

(核心)ant中沒有變量,但屬性和屬性。
@ {FOO}是用於訪問macrodef內部的macrodef屬性的值的語法,即:

<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> 

輸出:

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

參見Ant manual macrodef
鑑於$ {FOO}是訪問屬性值的語法:

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

輸出:

[echo] ${foo} => bar 

Ant manual property

+0

你打敗了我! :-) – 2012-03-09 22:19:38

+0

罷工;-)乾杯|| Slàintemhath – Rebse 2012-03-09 22:36:58