Himanshu Yadav
Himanshu Yadav

Reputation: 13585

Eclipse not compiling Groovy scripts into java classes at runtime

Strangely I am not having any compile-time error but while running the application I am getting NoClassDefFound error for Groovy classes.

I am using Eclipse 3.6 with Groovy 2.7.0 plugin. I have Groovy 1.8.5 installed on my machine and groovy-all.jar is in my classpath of application.

I can see all the groovy files in WEB-INF/classes folder with .groovy extension not with .class extension.

What I am missing here?

Upvotes: 8

Views: 10441

Answers (2)

user845279
user845279

Reputation: 2804

Make sure you are executing the code using groovy and not java. Otherwise, you will have to link the groovy.jar file in your classpath. See this discussion.

Upvotes: 2

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

Two possibilities:

  1. You project is not a groovy project and so your groovy files are being treated as resources (not sources). Resources are copied to the output folder, whereas sources are compiled. Make sure that your project icon has a little GR symbol on it.

  2. Or perhaps you have inadvertently enabled script folders for the source folder where your groovy files are located. Go to Preferences -> Groovy -> Compiler and look at the section on Groovy Script Folders. Note that Groovy Script folders can also be configured on a per-project basis, so you may also need to look at Project -> Properties -> Groovy Compiler.

Upvotes: 11

Related Questions