Eclipse 中的 Groovy 无法识别导入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9949213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 17:56:34  来源:igfitidea点击:

Groovy in Eclipse not recognizing imports

javaeclipsegroovy

提问by smcg

I am attempting to run a Groovy script in Eclipse but Eclipse is seemingly ignoring all of my import statements. If I hover over the errors it tells asks me to import the appropriate class (clicking on it does nothing).

我试图在 Eclipse 中运行 Groovy 脚本,但 Eclipse 似乎忽略了我的所有导入语句。如果我将鼠标悬停在错误上,它会要求我导入适当的类(单击它什么也不做)。

I have the required jars in my build path and class path.

我的构建路径和类路径中有所需的 jars。

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.

任何帮助,将不胜感激。

采纳答案by smcg

Forgot to actually build the project. Ouch. (build automatically was turned off in Eclipse)

忘记实际构建项目。哎哟。(在 Eclipse 中自动构建已关闭)

回答by Andrew Eisenberg

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. Check out your script folder at Preferences -> Groovy -> Compiler. Also, as of groovy-eclipse 2.6.1, there are project specific script folders, so also check in your project properties.
  1. 该脚本不在源文件夹中
  2. 所引用的脚本不在源文件夹中。
  3. 一个或两个脚本都在“脚本文件夹”中。脚本文件夹是脚本所在的文件夹。脚本文件夹中的 Groovy 文件不会发送到编译器,因此脚本文件夹中的脚本不能相互引用。在 Preferences -> Groovy -> Compiler 中查看您的脚本文件夹。此外,从 groovy-eclipse 2.6.1 开始,有项目特定的脚本文件夹,因此还要检查您的项目属性。

回答by Bruno Negr?o Zica

I was having this problem when I imported to the IDE an existing groovy project before having installed the "Groovy Development Tools" plugin.

当我在安装“Groovy 开发工具”插件之前将现有的 groovy 项目导入到 IDE 时,我遇到了这个问题。

I installed the Groovy plugin and restarted the IDE, but my project was still broken.

我安装了 Groovy 插件并重新启动了 IDE,但我的项目仍然损坏。

So I deleted the project and I imported it again, and then the problem was gone.

于是我把项目删了,重新导入,问题就解决了。

回答by Radoslav Ivanov

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"/>