Adding local JARs to Clojure projects in Leiningen 2

I’ve been working through Amit Rathore’s excellent book Clojure in Action, and was excited to start tinkering with accessing HBase from Clojure. However, I discovered that this was not straightforward.

Amit notes that “you’ll need to have the HBase JAR file on your classpath”. If you’re using Leiningen, it handles downloading your dependencies and adding them to your classpath, which is quite handy. I added the following to the :dependency item in my project definition in project.clj:

[org.apache.hbase/hbase "0.92.0"]

did a lein deps, and thought I’d be on my merry way.

Unfortunately, I promptly ran into a wall: attempts to instantiate the HBaseConfiguration class yielded a “NoClassDefFoundError” for org.apache.hadoop.conf.Configuration. I took a quick look at the JAR that Maven had downloaded for HBase, and sure enough, it didn’t contain that class. I had no problem downloading and running the HBase server, so I took a look through the JARs in the lib/ directory in that, and it turns out that this class is provided by hadoop-core-1.0.0.jar. Apparently the HBase project in Maven Central is missing a dependency.

Leiningen really wants all the JARs that your projects rely on to be managed by Maven; it doesn’t seem that there’s an easy way to just say “include this JAR”. However, it turns out that it’s not terribly difficult to create a local Maven repository. I followed the steps that I found on Paul Gross’s blog, adding -DcreateChecksum=true as suggested in the comments, to create a repository containing hadoop-core-1.0.0.jar, and I was up and running after another lein deps.

Leave a Reply