Debmalya Biswas Debmalya Biswas - 26 days ago 26
Groovy Question

Installing Groovy

Recently I downloaded Groovy-2.3.6 and try to install it on Linux system. I follow the instruction from http://groovy.codehaus.org/Installing+Groovy. I set my GROOVY_HOME variable.

export GROOVY_HOME=/home/work/Software/groovy-2.3.6


Then I set my environment path variable to the Groovy bin folder

export PATH=$PATH:/home/work/Software/groovy-2.3.6/bin


The JAVA_HOME variable is already created.

Now when I'm trying to run any command of Groovy, It generate following error

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groo/tool/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter. Program will exit.


I was going through some website to solve that problem. I find that if I set wrong path to GROOVY_HOME then it can happen. I can't figure out what should be the right path for that variable. Can anyone help me with this please.
Thanks

Answer

The simplest way to install Groovy on Linux/Mac is with SDKMAN. Here's what I suggest:

  • undo everything you've already done
  • install SDKMAN by running curl -s "https://get.sdkman.io" | bash
  • open a new terminal and install groovy with the command sdk install groovy 2.3.6

Going forward you can use SDKMAN to switch between different versions of Groovy (and Gradle, Grails, Griffon, etc.), install new versions, remove old versions, and so on.