This defines a new task using a
<sequential> nested task as a template. Nested elements <attribute> and <element> are used to specify attributes and elements of the new task. These get substituted into the <sequential> task when the new task is run. 下面是ant doc的一个example
<macrodef name="test"> 这里是macrodef的定义,定义了name属性
<attribute name="one"/> 参数定义,可以在macrodef外部调用
<attribute name="two" default="@{one}"/> 内部参数
<sequential>
实际执行的内容在sequential里
<echo>one=@{one} two=@{two}</echo>
</sequential>
</macrodef>
<test one="test"/> 外部调用
需要注意的是:
1、在整个build文件里macrodef是和target平级的。
2、macrodef可以调用其他macrodef,不可以调用target;target可以调用macrodef,也可以调用其他target
3、macrodef嵌套的时候,参数名称必须不同
比如上面的macrodef test,定义了one的参数
如果定义另外一个macrodef test2 也有一个参数,最好不要再叫one了,不然容易出现混乱
本文介绍了Ant中的macrodef元素,展示了如何使用它来定义新的任务模板,并通过实例详细解释了其属性和元素的使用方法。此外还提到了macrodef的一些使用限制。
145

被折叠的 条评论
为什么被折叠?



