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

时间:2011-10-12 19:32:10

标签: ant

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

谢谢!

1 个答案:

答案 0 :(得分: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>

第二个选项:更详细

<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>
相关问题