Running Groovy Script does not work with error: Could not find the main class: org.codehaus.groovy.tools.GroovyStarter

Answered

I looked into the documentation an imo set up the environment correctly but still Intellij Idea Community won't run that script. I need some help. The weird thing is, i can run groovysh and such perfectly fine from terminal.

I use Windows10 1803, groovy 2.3.7, Java 1.8.0_181 and IDEA 2018.3.6

 

PS: What i get from IDEA:

 

"C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-Dtools.jar=C:\Program Files\Java\jdk1.8.0_181\lib\tools.jar" -Dgroovy.home=C:\bin\apache-groovy-2.3.7 -Dgroovy.starter.conf=C:\bin\apache-groovy-2.3.7\conf\groovy-starter.conf -javaagent:C:\bin\ideaIC\lib\idea_rt.jar=61851:C:\bin\ideaIC\bin -Dfile.encoding=UTF-8 org.codehaus.groovy.tools.GroovyStarter --conf C:\bin\apache-groovy-2.3.7\conf\groovy-starter.conf --main groovy.ui.GroovyMain --classpath . [LIST OF ALL LIBRARIES] --encoding=UTF-8 C:\bin\ideaProjects\Intrexx\src\Testscript.groovy

0
8 comments
Avatar
Permanently deleted user

I uploaded it through https://uploads.services.jetbrains.com/

Filename: Intrexx.zip

 

When i try to run the Testscript.groovy within i get the error.

0

I can't reproduce the problem, make sure Groovy library is configured correctly and includes all the jars:

https://i.imgur.com/FWJt8FY.png
https://i.imgur.com/cOLVX43.png

GroovyStarter class resides in groovy-2.3.7.jar file. Double check you see it in the classpath of the command line when the script is started: https://i.imgur.com/q71gSLP.png

0
Avatar
Permanently deleted user

So i looked into the libraries listed in the classpath and the groovy-2.3.7.jar is listet in it.

0

See if reinstalling Groovy helps, this .jar may be damaged.

0
Avatar
Permanently deleted user

Solved it. Always used the wrong project type. I did use Java Project with Groovy Libs. When i use Groovy Project everything is fine. Anyway i am still wondering groovy code is not working in java projects.

0

Hi,

I have the same issue when trying to use Global Library. I need to Groovy script in version 2.4.13 which is not one of the default version option in IntelliJ IDEA when creating a new option. 

The strange thing is that if I create a new Project:

  1. File > New Project
  2. Select Groovy (project type)
  3. Build System: IntelliJ
  4. JDK: Oracle OpenJDK 21.0.3 (I have tried others)
  5. Groovy SDK:  2.4.21
  6. Add sample code: checked

The new project “Hello World!” sample runs perfectly. 

But if I try to switch Groovy versions Add a Global library > c:\Groovy\groovy-sdk-2.4.13\groovy-2.4.13\lib and try run the sample I get the same error:

Error: Could not find or load main class org.codehaus.groovy.tools.GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter

I tried to create another new Project but at point 5 above, select from Groovy SDK dropdown “Specify Groovy SDK Home” and select my c:\apache-groovy-sdk-2.4.13\groovy-2.4.13\lib folder it produces the same error. I is like IntelliJ does not like any other Groovy SDK library other than the one it will download itself when creating the project.

Please any ideas here as this is driving me mad.
 


 


 

 

0

Please try with JDK 11.

0

Please sign in to leave a comment.