问题
I have this code:
(ns test
(:gen-class))
(defn -main
[& args]
(println "hello!"))
But when I run java -cp clojure-1.6.0/clojure-1.6.0.jar clojure.main test.clj
I get no output. Why? How to fix this?
回答1:
Both ns
and defn
do not output anything. If you would like to print "hello!"
by invoking the -main
function, you have to add a function call at the end of the test.clj
file.
(ns test
(:gen-class))
(defn -main
[& args]
(println "hello!"))
(-main)
回答2:
You call the -main
function like so:
java -cp clojure-1.6.0/clojure-1.6.0.jar clojure.main -i test.clj -m test
-i
loads up a file
-m
launches the -main
function in a namespace
来源:https://stackoverflow.com/questions/30151387/cant-see-printed-values-if-launch-script-with-java