(需要)函数的clojure类路径问题? [英] clojure classpath problem for (require) function?
问题描述
CLASSPATH 将/Users/smcho/Desktop/clojure"作为其路径之一,该目录包含文件 hello.clj.
运行 clojure,然后运行 (require 'hello) 给出这个错误信息.
<前>java.io.FileNotFoundException: 无法在类路径上找到 hello__init.class 或 hello.clj: (NO_SOURCE_FILE:0)当我将目录更改为/Users/.../clojure"并运行相同的(需要 'hello)时,没有问题.这 .位于 CLASSPATH 上.
运行
<前>java -cp/Users/smcho/bin/jar/clojure.jar:/Users/smcho/Desktop/clojure clojure.lang.Repl也有效.
为什么clojure在CLASSPATH上找不到源码?
就像 Alex 提到的,如果你用 -cp 参数启动 java,那么 CLASSPATH 环境就不会被引用.所以,而不是
java -cp/Users/smcho/bin/jar/clojure.jar clojure.lang.Repl
使用
java -cp/Users/smcho/bin/jar/clojure.jar:$CLASSPATH clojure.lang.Repl
您可以从 Clojure repl 中检查您的 java 类路径:
(doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p)))
CLASSPATH has the "/Users/smcho/Desktop/clojure" as one of its path, and this directory has the file hello.clj.
Running clojure, and running (require 'hello) give this error message.
java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: (NO_SOURCE_FILE:0)
When I change directory to "/Users/.../clojure", and run the same (require 'hello), there's no problem. The . is on the CLASSPATH.
Running
java -cp /Users/smcho/bin/jar/clojure.jar:/Users/smcho/Desktop/clojure clojure.lang.Repl
also works.
Why clojure can't find the source on the CLASSPATH?
Like Alex mentioned, if you start java with the -cp argument, then the CLASSPATH environment is not referenced. So, instead of
java -cp /Users/smcho/bin/jar/clojure.jar clojure.lang.Repl
use
java -cp /Users/smcho/bin/jar/clojure.jar:$CLASSPATH clojure.lang.Repl
You can examine your java classpath from within the Clojure repl:
(doseq [p (.getURLs (java.lang.ClassLoader/getSystemClassLoader))] (println (.getPath p)))
这篇关于(需要)函数的clojure类路径问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!