[英]The taskdef ant task cannot be found
All - 全部 -
I'm following the most simplest instructions on this page: 我正在按照此页面上最简单的说明操作:
http://ant.apache.org/manual/develop.html http://ant.apache.org/manual/develop.html
However, when I try to execute the target "main" I get this error in netbeans: 但是,当我尝试执行目标“main”时,我在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: 但是这个错误没有意义,因为扩展“Task”的新Java类看起来像这样:
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: build.xml中的相关部分如下所示:
<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. 问题是Ant类加载器需要知道* .class文件所在的位置。
Once I changed the build.xml to look like: 一旦我将build.xml更改为:
<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="build/classes"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
it worked (ie it printed out the Hello World message). 它工作(即它打印出Hello World消息)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.