ant中调用外部ant任务的两种方法

本文详细介绍了在Ant脚本中如何通过antfile和exec两种方式调用外部任务,特别适用于多项目管理场景。包括使用antfile时设置dir、inheritall、inheritrefs的用途,以及使用exec命令直接调用系统控制台执行特定Ant任务的方法。

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

[url]http://blog.youkuaiyun.com/samlei/article/details/4231496[/url]

在ant脚本中对外部ant任务的调用,在多项目管理中特别有用。两种方法总结一下:

使用antfile、使用exec



一:使用antfile

<target name="copy_lib" description="Copy library files from  project1 to project2">
<ant antfile="build.xml"
dir="${project1dir}"
inheritall="false"
inheritrefs="false"
target="copy_to_project2_lib"
/>
</target>




antfile表示子项目的构建文件。
dir表示构建文件所再的目录,缺省为当前目录。

inheritall表示父项目的所有属性在子项目中都可使用,并覆盖子项目中的同名属性。缺省为true。
inheritrefs表示父项目中的所有引用在子项目中都可以使用,并且不覆盖子项目中的同名引用。缺省为false。
如果在ant任务中显示的定义引用,如上例<reference refid="filter.set">则该引用将会覆盖子项目中的同名引用。
target表示所要运行的子项目中的target,如果不写则为缺省target。



二:使用exec

<target name="copy_lib" description="Copy library files from  project1 to project2">
<exec executable="cmd.exe">
<arg line="/c "cd ../project1 && ant copy_to_project2_lib " "/>
</exec>
</target>




翻译为命令行就是:cmd.exe /c "cd ../project && ant copy_to_project2_lib"

意思是直接调用系统控制台,先执行cd命令,再执行ant脚本指定任务,/c 表示执行后续 String 指定的命令,然后停止。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值