2013-03-19 30 views
1

我正在嘗試爲Apache Ant編寫一個自定義任務(以下爲this tutorial)。自定義Ant任務中的「沒有兼容的構造函數」?

目前,我的任務是這樣的:

package my.package; 

import org.apache.tools.ant.BuildException; 
import org.apache.tools.ant.Task; 

class MyTask extends Task 
{ 
    private String command; 

    public void setCommand(String command) 
    { 
     this.command = command; 
    } 

    public void execute() throws BuildException 
    { 
     System.out.println(command); 
    } 
} 

我使用任務在我的構建文件如下:

<?xml version="1.0"?> 
<project name="TaskExample" default="main" basedir="."> 
    <taskdef name="mytask" classname="my.package.MyTask"/> 

    <target name="main"> 
    <mytask command="foobar" /> 
    </target> 
</project> 

當調用Ant的,我得到以下錯誤:

> ant -lib . 
Buildfile: /path/to/build.xml 

main: 

BUILD FAILED 
/path/to/build.xml:6: Could not create type mytask as the class class my.package.MyTask has no compatible constructor 

Total time: 0 seconds 

回答

4

在仍然輸入問題的同時找到解決方案。但也許這對其他人有用:

我簡單地在類聲明中忘記了public限定符。所以宣佈這個類如下完美:

package my.package; 

// ... 

// Mind the "public"! 
public class MyTask extends Task 
{ 
    // ... 
} 
相關問題