2012-11-04 83 views
4

我運行Windows 7,下面的代碼工作在Groovy控制檯AntBuilder工作:Groovy中控制檯但不是在Eclipse

def fileEx = new File(/Y:\Documents\Test File.txt/) 
def copyToFile = new File(/Y:\Documents\Test File - Copied by Groovy and Ant.txt/) 

ant = new AntBuilder() 
ant.copy(file:fileEx, tofile:copyToFile) 

但是當我嘗試運行它作爲一個Groovy腳本在Eclipse中,我得到這個錯誤:

Caught: java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException 
java.lang.NoClassDefFoundError: org/apache/tools/ant/BuildException 
    at copyFile.run(copyFile.groovy:4) 
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.BuildException 

我曾嘗試加入的ant.jar到myclasspath,無論是在Groovy的lib文件夾中的ant.jar和一個在Eclipse插件lib文件夾,但這並不解決問題。

回答

7

看起來像groovy-eclipse plugin附帶groovy完整安裝的庫的子集。除了eclipse插件之外,您還需要完整安裝groovy,您可能已經擁有它。

你應該能夠通過轉到你的項目,去Properties-> Java Build Path,然後點擊'Libraries'來解決你的問題。 '添加外部瓶子'並導航到您的完整groovy安裝。在那裏,lib目錄應該有ant.jar和ant-launcher.jar。添加它們兩個。這應該清除它(排隊調試的基本問題)。

+0

非常感謝。這解決了我的問題。我實際上將它們作爲外部罐子添加到安裝的JRE中,以便它們可用於我的所有項目。 –

相關問題