在蚂蚁的taskdef任务无法找到 [英] The taskdef ant task cannot be found
问题描述
全部 -
我在下面这个页面中最简单的说明:
http://ant.apache.org/manual/develop.html
然而,当我尝试执行目标主我得到这个错误在NetBeans中:
的taskdef类dec102012.MyAntTask不能使用ClassLoader AntClassLoader找到[]
块引用>但这个错误是没有意义的,因为我的扩展任务新的Java类看起来是这样的:
包dec102012;进口org.apache.tools.ant.BuildException;公共类MyAntTask扩展org.apache.tools.ant.Task {
私人弦乐味精; //执行任务的方法
公共无效的execute()抛出BuildException {
的System.out.println(MSG);
} //为消息属性的二传手
公共无效setMessage(弦乐味精){
this.msg =味精;
}
}在我的build.xml的相关部分如下:
<的taskdef NAME =mytask类名=dec102012.MyAntTaskCLASSPATH =dec102012/><目标名称=主>
< mytask消息=您好!世界MyVeryOwnTask作品/>
< /目标与GT;
解决方案问题是蚂蚁类加载器需要知道的* .class文件坐镇。
有一次,我改变了build.xml文件看起来像:
<的taskdef NAME =mytask类名=dec102012.MyAntTaskCLASSPATH =建立/班/> <目标名称=主>
< mytask消息=您好!世界MyVeryOwnTask作品/>
< /目标与GT;它的工作(即,它打印出来的Hello World消息)。
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>
解决方案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).
这篇关于在蚂蚁的taskdef任务无法找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!