如果没有命令行参数,则无法构建Ant

Pra*_*yag 4 ant

我在命令行将一个文件路径作为参数发送到ant.如果参数不存在,我希望构建失败.这样做的方法是什么?

谢谢!

Fai*_*Dev 5

在目标上使用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)