Installing Groovy from RPM on Fedora

I installed Groovy 1.6 on Fedora from an RPM as offered on the Groovy download page and immediately got an exception stack trace when running groovysh or groovyConsole. I installed the groovy-1.6.0-2.noarch.rpm file, kindly packaged by Federico Pedemonte, then tried to run groovyConsole:
[tom@dev ~]$ groovyConsole
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/tools/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter.  Program will exit.
I then tried to run groovysh with no better luck:
[tom@dev ~]$ groovysh
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/groovy/tools/GroovyStarter
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: org.codehaus.groovy.tools.GroovyStarter.  Program will exit.
The problem turned out to be quite simple to solve: a missing GROOVY_HOME. The packager adds the environment variable GROOVY_HOME to the shell by adding the file /etc/profile.d/groovy.sh so bash picks it up at startup via the /etc/profile script, but my current shell hadn't had a chance to read in that file yet.

The solution was as easy as exiting and starting a new shell, or manually setting:
[tom@dev ~]$ export GROOVY_HOME=/usr/share/groovy
[tom@dev ~]$ groovyConsole
and everything works.

One thought on “Installing Groovy from RPM on Fedora

  1. Hello!
    I’m the one who made that package 🙂
    I’m aware of the problem you mentioned, but haven’t yet found a clean solution to it.
    Anyway, a shorter solution to the problem is to issue a
    . /etc/profile
    to set the environment variables!
    Thanks for the credits in your post and happy groovying 🙂

Comments are closed.