Can't see printed values if launch script with `java`

ⅰ亾dé卋堺 提交于 2020-01-15 06:13:57

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!