简体   繁体   中英

AntBuilder works in Groovy Console but not in Eclipse

I am running Windows 7. The following code works in Groovy Console:

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)

but when I try to run it as a Groovy Script in Eclipse, I get this error:

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

I have tried adding ant.jar to myclasspath, both the ant.jar in the Groovy lib folder and the one in the Eclipse plugins lib folder, but this does not solve the problem.

Looks like groovy-eclipse plugin ships with a subset of libraries a full install of groovy does. You'll want a full install of groovy , which you may already have, in addition to the eclipse plugin.

You should be able to solve your problem by going to your project, and going to Properties->Java Build Path, then click 'Libraries'. 'Add External Jars' and navigate to your full groovy installation. Under there, the lib directory should have the ant.jar and ant-launcher.jar. Add them both. This should clear this up (and queue up the underlying problem for debugging).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM