简体   繁体   English

Eclipse没有在运行时将Groovy脚本编译成java类

[英]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. 奇怪的是,我没有任何编译时错误,但在运行应用程序时,我收到Groovy类的NoClassDefFound错误。

I am using Eclipse 3.6 with Groovy 2.7.0 plugin. 我使用Eclipse 3.6和Groovy 2.7.0插件。 I have Groovy 1.8.5 installed on my machine and groovy-all.jar is in my classpath of application. 我在我的机器上安装了Groovy 1.8.5,并且groovy-all.jar在我的应用程序类路径中。

I can see all the groovy files in WEB-INF/classes folder with .groovy extension not with .class extension. 我可以看到WEB-INF / classes文件夹中的所有groovy文件,扩展名为.groovy,扩展名不是.class。

What I am missing here? 我在这里缺少什么?

Two possibilities: 两种可能性:

  1. You project is not a groovy project and so your groovy files are being treated as resources (not sources). 您的项目不是一个常规项目,因此您的groovy文件被视为资源(而不是源)。 Resources are copied to the output folder, whereas sources are compiled. 资源被复制到输出文件夹,而源代码则被编译。 Make sure that your project icon has a little GR symbol on it. 确保项目图标上有一个小GR符号。

  2. Or perhaps you have inadvertently enabled script folders for the source folder where your groovy files are located. 或者您可能无意中为您的groovy文件所在的源文件夹启用了脚本文件夹。 Go to Preferences -> Groovy -> Compiler and look at the section on Groovy Script Folders. 转到首选项 - > Groovy - >编译器,然后查看Groovy脚本文件夹部分。 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. 请注意,Groovy Script文件夹也可以基于每个项目进行配置,因此您可能还需要查看Project - > Properties - > Groovy Compiler。

Make sure you are executing the code using groovy and not java . 确保使用groovy而不是java执行代码。 Otherwise, you will have to link the groovy.jar file in your classpath. 否则,您必须链接类路径中的groovy.jar文件。 See this discussion . 见这个讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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