Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AntBuilder works in Groovy Console but not in Eclipse

Tags:

eclipse

groovy

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.

like image 730
Jeremy Bartle Avatar asked Feb 19 '23 14:02

Jeremy Bartle


1 Answers

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).

like image 134
Brian Henry Avatar answered Feb 21 '23 07:02

Brian Henry