简体   繁体   中英

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. 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.

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

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. 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.

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

Had the same problem. Adding those to my .classpath solved the problem:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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