1

我有一个 build.xml,它有不同的 taskdef 动作。

从命令行运行时,我想根据要求调用 taskdef 操作,就像我们可以对 ant 目标执行的操作一样。

我的问题是如何从命令行运行 taskdef 操作。在此处附加示例代码,我只想从命令行运行第一个 taskdef helloworld。

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="MyTask" basedir="." default="use">
        <taskdef name="helloworld" classname="HelloWorld" classpath="${ant.project.name}.jar"/>
        <helloworld/>
<taskdef name="helloworld1" classname="HelloWorld1" classpath="${ant.project.name}.jar"/>
        <helloworld1/>
<taskdef name="helloworld2" classname="HelloWorld2" classpath="${ant.project.name}.jar"/>
        <helloworld2/>
</project>
4

1 回答 1

1

为每个任务创建一个单独的目标,如下所示。请注意默认的“使用”目标将如何运行所有三个任务:

<project name="MyTask" basedir="." default="use">

    <target name="use" depends="helloworld,helloworld1,helloworld2"/>

    <target name="helloworld">
        <taskdef name="helloworld" classname="HelloWorld" classpath="${ant.project.name}.jar"/>
        <helloworld/>
    </target>

    <target name="helloworld1">
        <taskdef name="helloworld1" classname="HelloWorld1" classpath="${ant.project.name}.jar"/>
        <helloworld1/>
    </target>

    <target name="helloworld2">
        <taskdef name="helloworld2" classname="HelloWorld2" classpath="${ant.project.name}.jar"/>
        <helloworld2/>
    </target>
</project>
于 2017-02-24T17:25:03.367 回答