在蚂蚁的taskdef任务不能被发现(The taskdef ant task cannot be

2019-08-03 22:47发布

全部 -

我下面这个页面中最简单的说明:

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

然而,当我尝试执行目标的“主”我知道在NetBeans此错误:

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

但这个错误是没有意义的,因为我的扩展“任务”新的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>

Answer 1:

问题是蚂蚁类加载器需要知道的* .class文件坐镇。

有一次,我改变了build.xml文件看起来像:

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

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

它的工作(即它打印出来的Hello World消息)。



文章来源: The taskdef ant task cannot be found
标签: java ant task