I want to distribute a Clojure program. Do I need a JDK or can a JRE handle everything in Clojure?
3 Answers
You only need the user to have a JRE (v1.5 or above)
Clojure programs can be compiled into a jar file. You don't have to use something like leiningen, but it's a lot easier.
Check out this page on the Clojure.org site for how to compile and run a program.
You can compile to a jar file from the REPL:
(compile 'clojure.examples.hello)
Here's how you would run a compile jar:
java -cp ./classes:clojure.jar clojure.examples.instance asdf
-
And will the Clojure "eval" command still work, even without a JDK? I don't understand how it could compile without a JDK Jan 27, 2011 at 9:25
-
2That's a good question. I think the answer is that the Clojure jar includes code that compiles Clojure to Java bytecode and does not use javac.– justinhjJan 27, 2011 at 18:36
-
2Pretty much yes. Here's the body of
eval
:(. clojure.lang.Compiler (eval form)))
. Jan 28, 2011 at 18:04 -
Technically, you don't need to even compile the clojure program into a jar file, right? Including the clojure jar and a simple shell script to run it (for convenience) should be sufficient. Oct 3, 2018 at 16:17
You just need a JRE.
https://github.com/technomancy/leiningen/blob/master/TUTORIAL.md explains in more detail, but I believe you just want an "Uberjar" which will contain all the dependencies that you need to distribute your application.