AntBuilder runs in Groovy console, but not in Eclipse

I am running Windows 7. The following code works in the 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 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 tried adding ant.jar to myclasspath, both ant.jar in the Groovy lib folder and the folder in the lib folder of Eclipse plugins, but this does not solve the problem.

+4
source share
1 answer

It looks like the groovy -eclipse plugin comes with a subset of libraries that performs a complete groovy installation. You will need the full groovy installation that you may already have, in addition to the eclipse plugin.

You must solve your problem by going to your project and going to “Properties-> Java Build Path”, then click “Libraries”. “Add external jars” and go to the full groovy installation. In this case, the lib directory should have ant.jar and ant -launcher.jar. Add them both. This should fix this (and queue the main problem for debugging).

+7
source

Source: https://habr.com/ru/post/1443914/


All Articles