编译Clojure?

j-g*_*tus 16 compilation clojure

我觉得这里有点傻,但是我无法编译Clojure Hello World.

目录结构:

hello-world/
  clojure-1.1.0.jar
  build/
    classes/
  src/
    test/
      hello.clj
Run Code Online (Sandbox Code Playgroud)

hello.clj:

(ns test.hello
  (:gen-class))

(defn -main [& args]
  (println "Hello" (nth args 0)))
Run Code Online (Sandbox Code Playgroud)

相互作用:

$ 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
Run Code Online (Sandbox Code Playgroud)

所以我可以从REPL加载并调用该文件,但它不能编译.

根据clojure.org,编译需要

  • 命名空间必须与classpath相关的文件路径匹配 - 检查
  • *compile-path*必须在类路径上 - 检查
  • :ns表格的gen-class参数 - 检查

一年前我发现这篇文章,据我所知,我做的完全相同,但它不起作用.

我错过了什么?

系统:OS X 10.6,Java 1.6.0,Clojure 1.1

j-g*_*tus 21

知道了,有第四个要求:

  • *compile-path*是相对于JVM工作目录解析的,通常是启动java的目录.或者通过REPL : (System/getProperty "user.dir"),

这样可行:

user=> (set! *compile-path* "build/classes")     
"build/classes"
user=> (compile 'test.hello)
test.hello
Run Code Online (Sandbox Code Playgroud)

  • 对我来说,(set!*compile-path*".")是编译当前目录中的CLJ所必需的. (4认同)

Ale*_*Ott 11

你为什么不使用莱宁根?使用它比使用手动编译代码要容易得多.您可以将我的文章用作介绍......