Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The taskdef ant task cannot be found

Tags:

java

task

ant

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>
like image 368
user1068636 Avatar asked Dec 12 '12 01:12

user1068636


Video Answer


1 Answers

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).

like image 98
user1068636 Avatar answered Sep 20 '22 12:09

user1068636