Clojure problem with classpath for function (require)?

CLASSPATH has "/ Users / smcho / Desktop / clojure" as one of its paths, and this directory has the hello.clj file.

Starting clojure and starting (require 'hello) gives this error message.

  java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: (NO_SOURCE_FILE: 0)

When I change the directory to "/Users/.../ clojure" and run the same thing (require "hello"), there is no problem .. is on CLASSPATH.

Performance

  java -cp /Users/smcho/bin/jar/clojure.jar:/Users/smcho/Desktop/clojure clojure.lang.Repl

also works.

Why can't clojure find the source in CLASSPATH?

+3
source share
2 answers

As Alex said, if you start java with the -cp argument, then the CLASSPATH does not reference. So instead

java -cp /Users/smcho/bin/jar/clojure.jar clojure.lang.Repl 

using

 java -cp /Users/smcho/bin/jar/clojure.jar:$CLASSPATH clojure.lang.Repl 

You can examine your java class path from Clojure repl:

 (doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p))) 
+7
source

You did not indicate which command you used for the first example, but note that if you use the -cp flag, the CLASSPATH environment variable is not referenced.

+4
source

All Articles