简体   繁体   English

Eclipse中的Groovy无法识别导入

[英]Groovy in Eclipse not recognizing imports

I am attempting to run a Groovy script in Eclipse but Eclipse is seemingly ignoring all of my import statements. 我试图在Eclipse中运行Groovy脚本,但Eclipse似乎忽略了我的所有import语句。 If I hover over the errors it tells asks me to import the appropriate class (clicking on it does nothing). 如果我将鼠标悬停在错误上,它会告诉我要导入相应的类(单击它不会执行任何操作)。

I have the required jars in my build path and class path. 我的构建路径和类路径中有必需的jar。

Sample code, pretty standard: 示例代码,非常标准:

package scripts.blah

import foo.Bar;

class FooMain {
    static main(String[] args){
        Bar bar = new Bar();
    }
}

Groovy:unable to resolve class Bar Groovy:无法解析类Bar

Any help would be appreciated. 任何帮助,将不胜感激。

Three possibilities: 三种可能性:

  1. The script is not in a source folder 该脚本不在源文件夹中
  2. The script being referred to is not in a source folder. 被引用的脚本不在源文件夹中。
  3. One or both scripts are in "script folders". 一个或两个脚本位于“脚本文件夹”中。 Script folders are folders where scripts go. 脚本文件夹是脚本所在的文件夹。 Groovy files in script folders are not sent to the compiler and therefore scripts in script folders cannot reference each other. 脚本文件夹中的Groovy文件不会发送到编译器,因此脚本文件夹中的脚本不能相互引用。 Check out your script folder at Preferences -> Groovy -> Compiler. 在Preferences - > Groovy - > Compiler中查看脚本文件夹。 Also, as of groovy-eclipse 2.6.1, there are project specific script folders, so also check in your project properties. 此外,从groovy-eclipse 2.6.1开始,还有项目特定的脚本文件夹,因此还要检查项目属性。

Forgot to actually build the project. 忘了实际构建项目。 Ouch. 哎哟。 (build automatically was turned off in Eclipse) (在Eclipse中自动关闭构建)

Had the same problem. 有同样的问题。 Adding those to my .classpath solved the problem: 将这些添加到我的.classpath解决了这个问题:

<classpathentry exported="true" kind="con" path="GROOVY_SUPPORT"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>

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

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