In taskdef, the value classpathrefmust be a reference to a previously defined one path. The path must include a jar archive that contains the class that implements the task, or it must point to a directory in the file system that is the root of the class hierarchy. This will not be the actual directory that your class contains if your class is in the package.
Here is an example.
MyTask.java:
package com.x.y.z;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
public class MyTask extends Task
{
public void execute() throws BuildException {
System.out.println( "MyTask is running" );
}
}
, com.x.y.z, -
, classes - :
$ ls classes/com/x/y/z
MyTask.class
build.xml, :
<project name="MyProject" basedir=".">
<path id="my.classes">
<pathelement path="${basedir}/classes" />
</path>
<taskdef name="mytask" classpathref="my.classes" classname="com.x.y.z.MyTask"/>
<mytask />
</project>
, classpathref classes - .
:
$ ant
Buildfile: .../build.xml
[mytask] MyTask is running
classpath, classpathref, :
<property name="my.classes" value="${basedir}/classes" />
<taskdef name="mytask" classpath="${my.classes}" classname="com.x.y.z.MyTask"/>