G$D/Groovy: Installing Groovy

by Marc Hedlund

Related link: http://groovy.codehaus.org/Installing+Groovy

(For an overview of the G$D/Groovy series, see <http://www.oreillynet.com/pub/wlg/5789>.)

Installing Groovy with a working ~/.groovy/lib

The Installing Groovy page contains concise and accurate directions for getting Groovy installed -- go ahead and follow them. (Note that you'll have to have Java installed already.) If you make your way to the Running Groovy page, though, you'll see a section called Adding Things to the Classpath. It reads (typos corrected):

When running command line scripts or interactive shells you might want to add things to your classpath such as JDBC drivers or JMS implementations, etc. To do this you have a few choices:

  • create a ~/.groovy/lib directory and add whatever jars you like there

  • add things to your CLASSPATH environment variable

  • pass -classpath (or -cp) into the command you used to create the shell or run the script

The second two options mentioned will work; by default, the first -- adding jars to ~/.groovy/lib -- will not (as of 1.0-beta6). You have to take one more step to complete your installation.

As documented in bug 429, a bug in a library Groovy depends on has led the Groovy developers to comment-out support for the ~/.groovy/lib directory. You can re-enable support for this library by:

  • Creating the ~/.groovy/lib directory;
  • Going to your GROOVY_HOME/conf directory;
  • Editing all of the *-classworlds.conf files so that

    # load user specific libraries
    #load ${user.home}/.groovy/lib/*

    is changed to

    # load user specific libraries
    load ${user.home}/.groovy/lib/*

After doing this, your ~/.groovy/lib directory will work.

I don't personally believe the groovy team has made the right call on this bug -- I'd rather have the interpreter create the ~/.groovy/lib directory on startup if it doesn't exist, and I'd rather the documentation were correct! But, once you know about it, it's an easy fix.