I have downloaded and installed a jar with Maven (as answered here) but now I need to require it inside of a project. I followed the instructions on the git README ((require '[clj-http.client :as client])
) but I still get this error:
FileNotFoundException Could not locate clj_http/client__init.class or clj_http/client.clj on classpath: clojure.lang.RT.load (RT.java:430)
The other answers on this thread will certainly work .... But adding jars directly on your machine's CLASSPATH or at the command line can be a very difficult strategy for development . . .
The most common, idiomatic way to include jars in a clojure app is Leiningen (easy, one step install on github -- begginers should check note at the end of this answer for a caveat)... Leiningen can also install the clojure environment and launch your repl for you, preloaded with the right jar environment.
It is essentially a java dependency manager and build tool rolled into one - i.e. like ivy or the maven Pom.xml which we use for java development.
A Few examples of how to use Leiningen to interact with multiple libs in a simple and scalable fashion :
To launch a repl, such that the jars in your project.clj file are on the classpath :
lein repl
To update your jars in your maven repo specified by your project.clj :
lein deps
Finally , lein let's you export "uberjars" which are akin to "fatjars", i.e. they have all the dependencies bundled for you.
A minor update regarding the new Lein version : Note for begginers.
There are two scripts you can run to install Leiningan, it might be safer to run this one:
https://github.com/jayunit100/leiningen/blob/stable/bin/lein (the stable release)
Rather than this one:
https://raw.github.com/technomancy/leiningen/preview/bin/lein (the latest update, which is a preview).
when you start the java process you need to do:
java -cp ./lib/clj-http.jar ./lib/clojure.jar clojure.main
Basically you need both clojure.jar (which is where the REPL is at) AND clj-http.jar in the classpath.
Assuming clj-http.jar is in ./lib/ directory. Or you could build your project with lein (build tool, similar to maven) and have it build an uberjar, which is what I would do. There's a pretty good walkthrough of setting up lein and building an uberjar here: http://zef.me/2470/building-clojure-projects-with-leiningen.
add clj-http.jar to CLASSPATH or CP before you start clojure repl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With