Execute compiled ClojureScript from the commandline with Rhino

你离开我真会死。 提交于 2019-12-12 02:46:10

问题


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

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