【问题标题】:Problem compiling in ClojureClojure 中的编译问题
【发布时间】:2009-03-03 17:37:14
【问题描述】:

我一直在尝试在 Clojure 中编译一个非常简单的 test.clj,但没有成功。我在Clojure Google Group 上有一个thread,有几个回复,但没有任何帮助。快速总结一下,这是我的 clojure 文件:

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

(defn -main
    [gre]
    (println (str "Hello " gre)))

基本上就是Clojure documentation中提供的示例文件。

我已将此文件适当地放在clojure/src/test/test.clj 中,并且应该能够使用(compile 'test.test) 进行编译,但我一直收到错误:

java.io.IOException: The system cannot find the path specified (test.clj:1)
这让我相信这是一个类路径问题。我尝试使用Clojure documenation 中给出的所有标准命令以及来自线程java -classpath .;src;classes;clojure.jar clojure.main 的最新建议运行Clojure。

如果有帮助,我的文件系统如下所示:

-+-clojure
 +-classes/
 +-+-src/
 | |-+-test/
 | | \-test.clj
 +-\-test.clj
 +-test.clj
 +-clojure.jar

附:我在 Vista Ultimate 上运行,所以它可能可能是权限问题,但我检查了权限并没有发现任何问题。

【问题讨论】:

    标签: java clojure compilation classpath


    【解决方案1】:

    在 Windows 上编译 test.clj 的控制台输出:

    C:\clojure>dir /b/s
    C:\clojure\classes
    C:\clojure\src
    C:\clojure\src\test
    C:\clojure\src\test\test.clj
    
    C:\clojure>java -cp c:\dev\clojure.jar;.\src;.\classes clojure.lang.ReplClojure
    user=> (compile 'test.test)
    test.test
    user=>
    

    生成的类文件在classes目录下。

    另外,请注意您在 main 中缺少右括号。更正版本:

    (ns test.test
        (:gen-class))
    
    (defn -main
        [gre]
        (println (str "Hello " gre)))
    

    【讨论】:

    • 太棒了!非常感谢,它就像一个魅力!另外,我要编辑这个问题,因为我刚刚从我所做的复制/粘贴中删除了这个问题。
    • 您好,我遇到了同样的问题。有什么问题?我试过你的解决方案: C:\clojure>java -cp clojure-1.0.0.jar;.\src;.\classes clojure.lang.Repl user=> (compile 'test.test) java.io.IOException: The系统找不到指定的路径(test.clj:1)
    • 这意味着您的 CLASSPATH 中没有 classes/ 目录。
    【解决方案2】:
     C:\clojrue\java -cp .\src;.\classes;clojure.jar 
        -Dclojure.compile.path=classes clojure.lang.Compile test.test
    

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 1970-01-01
      • 2011-03-08
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多