gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:35:52 25 4
gpt4 key购买 nike

正确的一个: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com