【发布时间】:2011-03-08 14:38:04
【问题描述】:
我在这里感觉有点傻,但我无法让 Clojure Hello World 编译。
目录结构:
hello-world/
clojure-1.1.0.jar
build/
classes/
src/
test/
hello.clj
你好.clj:
(ns test.hello
(:gen-class))
(defn -main [& args]
(println "Hello" (nth args 0)))
互动:
$ cd hello-world
[hello-world]$ java -cp ./clojure-1.1.0.jar:./build/classes:./src clojure.main
Clojure 1.1.0
user=> (require 'test.hello)
nil
user=> (test.hello/-main "there")
Hello there
nil
user=> (compile 'test.hello)
java.io.IOException: No such file or directory (hello.clj:2)
user=> *compile-path*
"classes"
user=> (doseq [p (.split (System/getProperty "java.class.path") ":")] (println p))
./clojure-1.1.0.jar
./build/classes
./src
nil
所以我可以从 REPL 加载和调用文件,但它无法编译。
根据clojure.org,编译需要
- 命名空间必须匹配类路径相对文件路径 - 检查
- *compile-path* 必须在类路径上 - 检查
- :ns 形式的gen-class 参数 - 检查
我找到了this post from a year back,据我所知,我的做法完全相同,但它不起作用。
我错过了什么?
系统:OS X 10.6、Java 1.6.0、Clojure 1.1
【问题讨论】:
-
看来我不能接受我自己的答案,所以我不得不让问题保持开放,直到其他人加入为止。
-
还需要注意的是,您很少需要 AOT 编译 Clojure 代码。 Clojure 代码无需编译就可以正常运行,这就是您应该运行它的方式。一些特定的 Clojure Java 互操作功能实际上要求您的代码是 AOT 编译的,但如果您不使用这些功能,请不要费心编译您的代码。如果你想要一个可执行的 jar,你可以只用一个 -main 函数来 AOT 编译一个主文件来运行应用程序。但是,assembla.com/spaces/clojure/tickets/…
标签: clojure compilation