java - Ant 构建中参数不完整的异常处理

标签 java ant

正确的一个:ant verifyParameters -DrestoreValue=false

例如:ant verifyParameters -Drestoreval=false

如果参数拼写错误,我想抛出一个错误,即使我传递多个参数,它也应该捕获所有参数并抛出错误。

最佳答案

不可能检查所有拼写错误的参数名称,因为每个参数名称本身都是有效的参数。拼写错误的可能性太多了。

但是您可以检查是否设置了正确的参数,如果缺少则失败。

这是一个例子。主目标 default 受到从属目标 check-parameter 的屏蔽,如果未设置参数 restoreValue,则该目标会失败。

<project name="option-test" default="default">

  <!--
    This is the main target. It depends on target check-parameter which fails,
    if parameter restoreValue is not set.
  -->
  <target name="default" depends="check-parameter">
    <echo message="Start build ..." />
    <echo message="restoreValue = ${restoreValue}" />
  </target>

  <!--
    This helper target sets property parameterok to true, if restoreValue is set.
    And to false, otherwise.
  -->
  <target name="check-is-set">
    <condition property="parameterok">
      <isset property="restoreValue"/>
    </condition>
  </target>

  <!--
    This target depends on target check-is-set, which calculates the parameterok property.
    The unless attribute evaluates the parameterok property, so that the target body
    is only excuted, if paramterok=false.
    So the build fails only if parameter restoreValue is not set.
  -->
  <target name="check-parameter" unless="${parameterok}" depends="check-is-set">
    <fail message="Parameter restoreValue not set!" />
  </target>

关于java - Ant 构建中参数不完整的异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45151683/

相关文章:

java - 绑定(bind)异常 : Address already in use even with unique port

JAVA线程并发

java - 如何在自定义 Ant 任务之间共享数据?

使用 Ant 构建 Android 应用程序

java - 如何强制代码样式格式化作为构建的一部分?

java - commandButton actionListener 调用 selectOneMenu 监听器

java - 如果正在使用不同的线程,则 Spring Cloud Stream 可轮询消费者 dlq 和 errorChannel 不起作用

java - 在Java中解析字符串的特定元素

java - Cordova 应用程序 - 在 Android 中使用铃声音量而不是媒体

java - 发布已存在的 jar 文件