ant中利用macrodef来定义可重用的task

本文介绍了Ant中的macrodef元素,展示了如何使用它来定义新的任务模板,并通过实例详细解释了其属性和元素的使用方法。此外还提到了macrodef的一些使用限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先来看下macrodef的说明

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了,不然容易出现混乱


转载于:https://www.cnblogs.com/feiweiwei/archive/2009/05/18/1459570.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值