我有一个蚂蚁脚本:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntTest" basedir="." default="clean">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<target name="clean" description="delete all generated files">
<delete dir="${classes.dir}" failonerror="false"/>
<echo message="Hello" />
<delete dir="${ant.project.name}.jar"/>
</target>
<target name="compile" description="compile the task">
<mkdir dir="${classes.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" description="create jars of task" depends="compile">
<jar destfile="${ant.project.name}.jar" basedir="${classes.dir}" />
</target>
<target name="use" description="use the created jars" depends="jar">
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar" />
<ntTest/>
</target>
</project>
输出为
Buildfile: D:WorkD3000AntTestBuild.xml
clean:
[delete] Deleting directory D:WorkD3000AntTestclasses
[echo] Hello
compile:
[mkdir] Created dir: D:WorkD3000AntTestclasses
[javac] Compiling 1 source file to D:WorkD3000AntTestclasses
compile:
jar:
[jar] Building jar: D:WorkD3000AntTestAntTest.jar
compile:
jar:
use:
BUILD FAILED
D:WorkD3000AntTestBuild.xml:24: taskdef class AntTest cannot be found
using the classloader AntClassLoader[D:WorkD3000AntTestAntTest.jar]
Total time: 758 milliseconds
有人能告诉我为什么会出现这个错误吗:
BUILD失败D:\Work\D3000\AntTest\BUILD.xml:24:taskdef类AntTest使用类加载器找不到AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
我的类文件包含名为AntTest
的类
似乎类名错误,您需要完全限定的类名
而不是:
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar"/>
尝试:
<taskdef name="ntTest" classname="com.yourdomain.AntTest" classpath="${ant.project.name}.jar"/>