在目标上使用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>
Run Code Online (Sandbox Code Playgroud)
第二种选择:更详细
<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>
Run Code Online (Sandbox Code Playgroud)