繁体   English   中英

用于在任务名称中使用连字符运行Ant任务的命令行

[英]Command line to run the Ant task with hyphen in the task name

任务名称以连字符“ - ”开头。

<?xml version="1.0" encoding="UTF-8"?>
<project name="proj">
    <target name="-task1">
        <echo>Done!</echo>
    </target>
</project>

从命令行运行ant脚本时如何指定此任务? 这不起作用:

ant -task1 -f test.xml

将任务名称括在引号中。

ant "-task1" -f test.xml

更新:来自Ant文档

Targets beginning with a hyphen such as "-restart" are valid,
and can be used to name targets that should not be called directly
from the command line.
For Ants main class every option starting with hyphen is an option for Ant itself
and not a target. For that reason calling these target from command line is not
possible. On the other hand IDEs usually don't use Ants main class as entry 
point and calling them from the IDE is usually possible.

有些人用破折号启动内部目标只是为了确保用户无法从命令行运行它们。 事实上,我将所有内部目标都作为标准做法-仅仅是因为这个原因。

你可以尝试旧的双击法技巧。 我没有在我当前的系统上安装Ant,所以我无法测试它。 双破折号是一种常见的Unix技巧,当你有文件和以破折号开头的东西时,大多数命令都会用它来帮助结束参数。 顺便说一句,任务应该是命令行上的最后一件事:

$ ant -f test.xml -- -task1

更糟糕的是,您可以在build.xml文件中定义另一个目标,该目标依赖于此目标并带有破折号:

<task name="sneaky"
    depends="-task1"/>

然后你应该可以打电话给sneaky

$ant -f test.xml sneaky

来自ANT目标文档

以连字符开头的目标(如“-restart”)有效,可用于命名不应直接从命令行调用的目标。 对于Ants主类,每个以连字符开头的选项都是Ant本身的选项,而不是目标。 因此,无法从命令行调用这些目标。

因此,用户无法使用命令行中的连字符调用目标。

2016年4月21日在Windows平台上测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM