Clojure在本地目录中找不到.clj。和CLASSPATH上的./classes [英] Clojure can't find .clj in local directory, . and ./classes on CLASSPATH
问题描述
当我评估(使用'hello)加载hello.clj时,REPL会出现以下错误:
java .io.FileNotFoundException:无法在类路径上找到hello__init.class或hello.clj:(NO_SOURCE_FILE:0)
我调用REPL像这样:
java -cp/ Library / Java / Extensions / servlet- 2.5-20081211.jar:...很多jarfiles ...:/ Library / Java / Extensions / clojure-contrib.jar:/Library/Java/Extensions/clojure-1.0.0.jar:./ classes /:。 。 jline.ConsoleRunner clojure.lang.Repl
阅读,这看起来像是找不到文件在PWD,但我已经添加。到没有成功的路径: - (。
在OS X 10.6上使用Java 1.6运行。
我确定我是一个白痴,有人可以打我一个LART?
编辑:我也试过了 ClojureX distro,并得到相同的结果。
如果 hello.clj
在 $ DIR
和 $ DIR
在您的类路径上,则 hello.clj
需要以(ns hello)
c $ c> $ DIR / $ SUBDIR 和 $ DIR
是在你的类路径上,那么hello.clj需要以(ns $ SUBDIR.hello)
。一般来说,你的文件名结构和ns名称结构必须匹配,在ns中文件名分隔符替换为。
名称和任何 _
s在文件名对应于 -
在ns名称实际文件的名称需要成为命名空间名称的最终组件(可能是唯一的组件,如果文件的dir在类路径上)。
EDIT:
一个扩展示例。除了我上面写的信息,所以请跳过它,如果这是足够的你;但是我知道,在开始阶段,让我感到痛苦,所以我决定以一步一步的方式写这个,所以某人可能会幸免于特定的学习经验;-)。
说这是您的命名空间定义:
;;;在文件hello.clj
(ns hello)
(defn hello []
(printlnHello!))
然后,如果您在类路径中放置包含 hello.clj
的目录,去,并在REPL的(使用'hello)
应该做你想要的。
另一方面,你这样做:
;;;在文件hello.clj
(ns my-namespace)
;;; ...
或:
;;;在文件my-filename.clj
(ns hello)
;;; ...
- 也就是说,如果您在文件名称和
此外,如果你把 hello.clj
在 / path / to / code
,但你在你的类路径实际上是 / path / to
即 / path / to / code
的父目录,您需要这样做:
;;;在文件/path/to/code/hello.clj
(ns code.hello)
;;; ...
然后你就可以最后,如果你调用你的文件
my_namespace.clj
,你就可以需要调用你的ns my-namespace
(反之亦然)。 _
在文件名中不应该使用。
在命名空间名称和
-
When I evaluate (use 'hello) to load hello.clj, the REPL complains with the following error:
java.io.FileNotFoundException: Could not locate hello__init.class or hello.clj on classpath: (NO_SOURCE_FILE:0)
I'm invoking the REPL like this:
java -cp "/Library/Java/Extensions/servlet-api-2.5-20081211.jar:... lots of jarfiles ...:/Library/Java/Extensions/clojure-contrib.jar:/Library/Java/Extensions/clojure-1.0.0.jar:./classes/:." jline.ConsoleRunner clojure.lang.Repl
Reading around, this looks like the file isn't being found in the PWD, but I've added . to the path with no success :-(.
Running with Java 1.6 on OS X 10.6.
I'm sure I'm being an idiot, can someone hit me with a LART?
EDIT: I also tried the ClojureX distro, and got the same results.
If hello.clj
is in $DIR
and $DIR
is on your classpath, then hello.clj
needs to start with (ns hello)
. If it's in $DIR/$SUBDIR
and $DIR
is on your classpath, then hello.clj needs to start with (ns $SUBDIR.hello)
. Generally, your filename structure and the ns name structure must match, with filename separator replaced by .
in ns name and any _
s in the filename corresponding to -
s in the ns name. The name of the actual file needs to be the final component (possibly the only component, if the file's containing dir is on the classpath) of the namespace name.
EDIT:
An extended example. No information beyond what I've written above, so please skip over it if that was enough for you; however I know that getting CP right was quite painful for me in the beginning, so I decided I'd write this out in a step by step fashion so that someone, somewhere might perhaps be spared that particular `learning experience' ;-).
Say this is your namespace definition:
;;; in file "hello.clj"
(ns hello)
(defn hello []
(println "Hello!"))
Then if you put the directory containing hello.clj
on your classpath, you're good to go and a (use 'hello)
at the REPL should do what you want.
If, on the other hand, you do this:
;;; in file "hello.clj"
(ns my-namespace)
;;; ...
or this:
;;; in file "my-filename.clj"
(ns hello)
;;; ...
-- that is, if you introduce a mismatch between the name of the file and the name of the namespace, Clojure won't be able to find your namespace.
Also, if you put hello.clj
in /path/to/code
, but what you have on your classpath is actually /path/to
, i.e. the parent directory of /path/to/code
, you need to do this:
;;; in file "/path/to/code/hello.clj"
(ns code.hello)
;;; ...
Then you'll be able to (use 'code.hello)
.
Finally, if you call your file my_namespace.clj
, you need to call your ns my-namespace
(and the other way around). _
s in namespace names and -
s in filenames should not be used.
这篇关于Clojure在本地目录中找不到.clj。和CLASSPATH上的./classes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!