Here I check the environment variable CLASSPATH
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ echo $CLASSPATH
/home/daniel/ps/clojure/projects/ring-tutorial/src
Here I check what java thinks it is.
daniel@daniel-laptop:~/ps/clojure/projects/ring-tutorial$ lein repl
Clojure 1.1.0
user=> (System/getProperty “java.class.path”)
“src/:classes/:/home/daniel/.m2/repository/leiningen/leiningen/1.1.0/leiningen-1.1.0-standalone.jar:lib/clojure-1.1.0.jar:lib/servlet-api-2.5-6.1.14.jar:lib/commons-io-1.4.jar:lib/clj-stacktrace-0.1.0.jar:lib/clojure-contrib-1.1.0.jar:lib/ring-devel-0.2.0.jar:lib/jetty-util-6.1.14.jar:lib/clj-html-0.1.0.jar:lib/ring-jetty-adapter-0.2.0.jar:lib/jetty-6.1.14.jar:lib/ring-core-0.2.0.jar:lib/commons-fileupload-1.2.1.jar:lib/ring-servlet-0.2.0.jar:lib/commons-codec-1.4.jar:”
As you can see, the two responses are completely different. I’m pretty sure that I must just be misunderstanding where I ought to be editing the CLASSPATH variable for java to “get it,” except that everything I’ve found says that this should work. So what’s the deal? Does leiningen spawn its own weird renegade instance of clojure? Am I editing a completely irrelevant variable? Any help much appreciated.
$CLASSPATHis indeed completely irrelevant here. It is whatjava-the-JVM-launcher-programme would use if no classpath information was provided to it on the command line; Leiningen provides the JVM with a classpath appropriate to whichever project you’re working on.In this particular case,
"/home/.../ring-tutorial/src"would not be a very useful classpath for the Ring tutorial, since it only includes the Ring tutorial’s source and does not include the Clojure jar (which is necessary for running Clojure code), the Ring jars (Ring is a multi-module project) or any of the other jars Ring depends on. The classpath produced by Leiningen might seem pretty long, but all of its components really need to be there.Incidentally, if you’re just starting out with Clojure, I’d recommend you stick to your toolchain’s classpath management facilities (that might mean Emacs +
lein swankor some IDE + the Clojure plugin) if at all possible. Otherwise, there’s a lot of questions on Clojure classpath issues here on SO, plus a multitude of other resources on the topic you can google for… but now that tool support is pretty robust and you don’t normally need to touch classpath by hand, it’s just pain best avoided in the beginning.