Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add directory to Clojure's classpath?

Tags:

java

clojure

I have installed the libraries with Maven to the ~/.m2/repository/ directory. I would like to add that path to the default Clojure classpath. I could not find the documentation how to do that.

Any hints?

Cheers!

clj
Clojure 1.4.0
user=> (require '[clojure.java.jmx :as jmx])
FileNotFoundException Could not locate clojure/java/jmx__init.class or clojure/java/jmx.clj on classpath:   clojure.lang.RT.load (RT.java:432)

The class path by default is:

user=> (println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
(#<URL file:/Users/myuser/cljmx/> #<URL file:/usr/local/Cellar/clojure/1.4.0/clojure-1.4.0.jar> #<URL file:/Users/myuser/cljmx/>)
nil
like image 736
Istvan Avatar asked Aug 15 '12 17:08

Istvan


1 Answers

I assume that clj is a script to start Clojure REPL. Take a look into this script and find line similar to this:

java -cp /path/to/clojure.jar clojure.main

Here you start class clojure.main having "clojure.jar" on your classpath. To add more jars just add them to the end of -cp option values. E.g. on Linux:

java -cp /path/to/clojure.jar:/path/to/mylib.jar clojure.main

(use ; instead of : on Windows)

However, very soon you'll get tired of this way and will look for project management tool. So it makes sense to start using it right now. Take a look at Leiningen - it manages dependencies for you based on Maven (so it will be extremely easy to add new jar) and has REPL.

like image 192
ffriend Avatar answered Oct 20 '22 00:10

ffriend