The taskdef ant task cannot be found
52,374
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).
Author by
user1068636
Updated on July 05, 2022Comments
-
user1068636 almost 2 years
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>