AntBuilder可以在Groovy控制台中工作,但不能在Eclipse中工作

AntBuilder可以在Groovy控制台中工作,但不能在Eclipse中工作,eclipse,groovy,Eclipse,Groovy,我正在运行Windows7。以下代码在Groovy控制台中工作: 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) 但当我尝试在Eclipse中以G

我正在运行Windows7。以下代码在Groovy控制台中工作:

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)
但当我尝试在Eclipse中以Groovy脚本的形式运行它时,会出现以下错误:

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插件库文件夹中的ant.jar,但这并没有解决问题。

看起来Groovy的完整安装会带来库的子集。除了eclipse插件之外,您还需要完整安装,您可能已经安装了


您应该能够通过转到项目,转到属性->Java构建路径,然后单击“库”来解决问题添加外部JAR并导航到groovy的完整安装。在那里,lib目录应该有ant.jar和ant-launcher.jar。把它们都加起来。这应该可以解决这个问题(并将潜在问题排成队列进行调试)。

非常感谢。这解决了我的问题。实际上,我将它们作为外部JAR添加到已安装的JRE中,以便它们可用于我的所有项目。