问题
I understand ClojureScript can be executed within a JavaScript REPL or it can be compiled into JavaScript, then run in a browser. I couldn't find a way to use it on the server side with Rhino. Here is my way of thinking, I have a simple source file:
(ns simple.hello)
(println "Hello, world")
I compile it to hello.js
. I try to run
java -jar js.jar out/goog/base.js out/goog/deps.js out/hello.js
Nothing happens. How can I make it work, or is only Node.js supported on the command line?
回答1:
This works for me:
src/app.js:
(ns simple.app)
(ns hello)
(defn ^:export greet [n]
(print (str "Hello " n)))
(greet "World")
To compile:
cljsc src '{:optimizations :advanced}' > app-prod.js
Then, to run with Rhino:
java -jar js.jar app-prod.js
Output: Hello World
Hope that helps!
来源:https://stackoverflow.com/questions/7738135/execute-compiled-clojurescript-from-the-commandline-with-rhino