我有一个按顺序执行2个步骤的Ant目标:
I have an Ant target that executes 2 steps in sequence:
<target name="release"> <antcall target="-compile"/> <antcall target="-post-compile"/> </target>使用上述脚本,如果"-compile"目标失败,它将立即退出. "-post-compile"没有运行的机会.有没有办法确保即使第一步(编译)失败了,也要执行第二步(编译后)?
With the above script, it quits immediately if the "-compile" target fails. "-post-compile" does not get a chance to run. Is there a way to make sure the second step (-post-compile) is executed even if the 1st one (-compile) fails?
推荐答案如果您使用的是ant-contrib(这很常见),则可以使用 尝试捕获任务 ,并将您的post-compile调用放入其finally元素.
If you are using ant-contrib (which is very common), you could make use of the try-catch task and put your post-compile call into its finally element.
此外,如果您不是使用ant-contrib,则可以使用 subant 任务来调用您的compile目标. subant具有failonerror属性,您可以使用该属性单独忽略失败的目标. 任务描述页面上的许多用法示例.
Also, if you are not using ant-contrib, then you might use the subant task to call your compile target. subant has a failonerror attribute, which you can use to individually ignore failed targets. Lots of usage examples on the task description page.
更多推荐
遇到错误时,Ant可以继续吗?
发布评论