2012-12-12 156 views
9

全部 -的的taskdef Ant任務無法找到

我下面這個頁面中最簡單的指令:

http://ant.apache.org/manual/develop.html

然而,當我嘗試執行目標「主」我在NetBeans得到這個錯誤:

taskdef class dec102012.MyAntTask cannot be found using the classloader AntClassLoader[] 

但這錯誤是沒有意義的,因爲我的擴展「任務」新的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> 
+0

刪除'classpath =「dec102012」' –

+0

當我這樣做時,我得到相同的錯誤。 – user1068636

回答

11

問題是螞蟻類加載器需要知道* .class文件的位置。

一旦我改變了build.xml文件看起來像:

<taskdef name="mytask" classname="dec102012.MyAntTask" classpath="build/classes"/> 

    <target name="main"> 
    <mytask message="Hello World! MyVeryOwnTask works!"/> 
    </target> 

它的工作(即它打印出來的Hello World消息)。

相關問題