ant - 如何在错误键入的 ant 目标上显示信息更丰富的错误消息?

标签 ant

当我们的一位开发人员错误输入无法识别的 ant 目标名称时,结果是一条不友好的错误消息,例如:

BUILD FAILED
Target "foo" does not exist in the project "bar". 

我更喜欢它运行一个显示可用目标列表的目标。有没有办法捕获 ant 错误消息并运行另一个目标或某种自定义错误消息?

谢谢。

最佳答案

错误消息非常用户友好。它明确指出指定的目标不存在于 build.xml 文件中。也许非技术用户会对简洁的错误 消息感到烦恼。 (什么是目标?什么是项目“栏”?)但是,程序员应该有足够的技术来阅读消息并意识到他们的错误。

开发人员可以通过 ant --projecthelp 显示所有外部 目标命令。可以缩写为ant -p .

您可以通过添加 description 来帮助该过程开发人员可以使用的有效目标的参数。如果您的 build.xml 中有单个目标有一个 description参数,ant --projecthelp只会显示带有 description 的目标参数。

您还可以添加 <description>任务到你的顶部 build.xml文件以显示有关项目的信息。这是一个简单的例子:

<project name="Fubar" default="foo">

    <description>
        Project Fubar is a highly secret project that you shouldn't know
        anything about. If you have read this, you've violated national
        security guidelines and must be terminated with extreme finality.
        Hey, it hurts me more than  it hurts you.
    </description>

    <target name="foo"
        description="Runs target &quot;foo&quot;"/>

    <target name="fu"/>     <!-- Internal target No description -->

    <target name="bar"
        description="Runs target &quot;bar&quot;"/>
</project>

这是我的 ant -p输出:

$ ant --projecthelp
Buildfile: build.xml

        Project Fubar is a highly secret project that you shouldn't know
        anything about. If you have read this, you've violated national
        security guidelines and must be terminated with extreme finality.
        Hey, it hurts me more than  it hurts you.

Main targets:

 bar  Runs target "bar"
 foo  Runs target "foo"
Default target: foo
$

请注意,我的 build.xml 中有三个目标, 但目标 fu未提及,因为它只是一个内部目标。

关于ant - 如何在错误键入的 ant 目标上显示信息更丰富的错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4717583/

相关文章:

java - Tomcat 8 升级后的 JNDI NameNotFoundException

maven-2 - maven, Ant 插件,antrun :run

基于 Ant 构建的 Java 项目布局最佳实践

java - ant 中的 unix2dos(或 dos2unix)

android - crosswalk cordova android 更新项目?

java - 为什么没有人使用 make for Java?

ant - 如何覆盖 Jenkins 中的 http_proxy 环境变量?

ant - 如何使用 'loadfile'任务将文件加载到ant中的变量中?

xml - 转换输出中不需要的字符编码转换

java - 循环内循环迭代 6 次,但打印 9 次而不是 3 次