【问题标题】:The taskdef ant task cannot be found找不到taskdef ant任务
【发布时间】:2012-12-12 01:10:45
【问题描述】:

全部 -

我正在遵循此页面上最简单的说明:

http://ant.apache.org/manual/develop.html

但是,当我尝试执行目标“main”时,我在 netbeans 中收到此错误:

taskdef class dec102012.MyAntTask cannot be found using the classloader AntClassLoader[]

但是这个错误没有意义,因为我扩展“Task”的新 Java 类看起来像这样:

package dec102012;

import org.apache.tools.ant.BuildException;

public class MyAntTask extends org.apache.tools.ant.Task{
    private String msg;

    // The method executing the task
    public void execute() throws BuildException {
        System.out.println(msg);
    }

    // The setter for the "message" attribute
    public void setMessage(String msg) {
        this.msg = msg;
    }
}

我的 build.xml 中的相关部分如下所示:

<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="dec102012"/>

<target name="main">
    <mytask message="Hello World! MyVeryOwnTask works!"/>
</target>

【问题讨论】:

  • 删除classpath="dec102012"
  • 我这样做时遇到了同样的错误。

标签: java ant task


【解决方案1】:

问题是 Ant 类加载器需要知道 *.class 文件的位置。

一旦我将 build.xml 更改为如下所示:

<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="build/classes"/>

  <target name="main">
    <mytask message="Hello World! MyVeryOwnTask works!"/>
  </target>

它起作用了(即它打印出 Hello World 消息)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 2010-10-03
    • 2012-05-26
    • 2010-11-17
    • 1970-01-01
    • 2015-03-12
    相关资源
    最近更新 更多