How To: Run Clojure with Clojure-Contrib Library

I recently picked up Programming Clojure and started working through it, trying to wrap my head around this new variant of Lisp.

Installing clojure itself was pretty simple (sudo apt-get install clojure, since I’m using Ubuntu), but I had a hard time figuring out how to make the clojure contrib libraries available from the clojure REPL (I kept getting errors about the clojure-contrib classes not being on the classpath).

Here’s how you do it: start the clojure REPL with an extra argument pointing to where you’ve installed the source files for clojure-contrib. For example:

clojure -cp /home/rontoland/Code/clojure-contrib-1.1.0/src

Since the clojure-contrib libraries are used throughout the book, I put the above code in a small script and saved it in my /usr/local/bin folder as clojure-repl, so I don’t have to remember the longer command.

Ron Toland @mindbat