我在命令行将文件路径作为参数发送给 ant。如果参数不存在,我希望构建失败。有什么方法可以做到这一点?
谢谢!
最佳答案
在目标上使用 if 属性,例如:
<project name="test" default="init">
<target name="init" if="${path}">
<!--This will only execute if ${path} is defined from the command line-->
</target>
</project>
第二个选项:更详细
<project name="test" default="init">
<target name="init">
<fail message="Path is not set! Exiting ant script!">
<condition>
<not>
<isset property="${path}"/>
</not>
</condition>
</fail>
</target>
</project>
关于ant - 如果没有命令行参数,Ant 构建会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7745481/