[英]The taskdef ant task cannot be found
全部 -
我正在按照此頁面上最簡單的說明操作:
http://ant.apache.org/manual/develop.html
但是,當我嘗試執行目標“main”時,我在netbeans中遇到此錯誤:
taskdef class dec102012.MyAntTask cannot be found using the classloader AntClassLoader[]
但是這個錯誤沒有意義,因為擴展“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;
}
}
build.xml中的相關部分如下所示:
<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="dec102012"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
問題是Ant類加載器需要知道* .class文件所在的位置。
一旦我將build.xml更改為:
<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="build/classes"/>
<target name="main">
<mytask message="Hello World! MyVeryOwnTask works!"/>
</target>
它工作(即它打印出Hello World消息)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.