Problem compiling in Clojure

2020-07-10 07:23发布

问题:

I've been trying to compile a very simple test.clj in Clojure without any success. I have a thread on the Clojure Google Group with several responses, but nothing has helped. To quickly summarize, here is my clojure file:

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

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

Basically it's the example file provided in the Clojure documentation.

I have placed this file appropiately in clojure/src/test/test.clj, and should be able to compile with (compile 'test.test), but I keep getting the error:

java.io.IOException: The system cannot find the path specified (test.clj:1)
which leads me to believe it is a classpath problem. I have tried running Clojure with all the standard commands given in the Clojure documenation as well as the latest suggestion from the thread java -classpath .;src;classes;clojure.jar clojure.main.

If it helps, my filesystem looks like this:

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

P.S. I am running on Vista Ultimate so it may possibly be a permissions problem, but I have checked the permissions and could not find anything wrong with them.

回答1:

Console output for compiling test.clj on Windows:

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=>

The generated class files are in the classes directory.

Also, note that you're missing a right parenthesis in your main. Corrected version:

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

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


回答2:

 C:\clojrue\java -cp .\src;.\classes;clojure.jar 
    -Dclojure.compile.path=classes clojure.lang.Compile test.test