The taskdef ant task cannot be found

不羁岁月 提交于 2019-12-10 02:42:01

问题


All -

I'm following the most simplest instructions on this page:

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

However, when I try to execute the target "main" I get this error in netbeans:

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

But this error does not make sense because my new Java class that extends "Task" looks like this:

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;
    }
}

The relevant portion in my build.xml looks like:

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

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

回答1:


The problem is the Ant Classloader needs to know where the *.class file sits.

Once I changed the build.xml to look like:

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

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

it worked (i.e. it printed out the Hello World message).



来源:https://stackoverflow.com/questions/13831194/the-taskdef-ant-task-cannot-be-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!