我有一个蚂蚁脚本:
<?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:\Work\D3000\AntTest\Build.xml
clean:
[delete] Deleting directory D:\Work\D3000\AntTest\classes
[echo] Hello
compile:
[mkdir] Created dir: D:\Work\D3000\AntTest\classes
[javac] Compiling 1 source file to D:\Work\D3000\AntTest\classes
compile:
jar:
[jar] Building jar: D:\Work\D3000\AntTest\AntTest.jar
compile:
jar:
use:
BUILD FAILED
D:\Work\D3000\AntTest\Build.xml:24: taskdef class AntTest cannot be found
using the classloader AntClassLoader[D:\Work\D3000\AntTest\AntTest.jar]
Total time: 758 milliseconds
有人能告诉我为什么会出现这个错误:
BUILD FAILED D:\ Work \ D3000 \ AntTest \ Build.xml:24:taskdef class AntTest 无法使用类加载器找到 AntClassLoader [d:\工作\ D3000 \ AntTest \ AntTest.jar]
我的类文件包含名为AntTest
答案 0 :(得分:0)
似乎类名错误,您需要完整的合格类名
而不是:
<taskdef name="ntTest" classname="AntTest" classpath="${ant.project.name}.jar"/>
尝试:
<taskdef name="ntTest" classname="com.yourdomain.AntTest" classpath="${ant.project.name}.jar"/>