【发布时间】:2026-01-22 13:10:02
【问题描述】:
我运行的是 Windows 7。以下代码在 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 plugins lib 文件夹中的 ant.jar,但这并不能解决问题。
【问题讨论】: