Could you please tell how to build a jar file from clojure source code on window xp, Wihout using maven or such software? Only clojure and Windows XP
1 Answer
Without any tool, you're bound to do some quirky steps manually. Say you have clojure.jar in the current directory, along with a target folder for compilation named classes and a clojure source file in src/awesome.clj with the following code:
(ns awesome)
(defn life-universe-and-everything []
(println "42"))
In order to compile it you will issue the following commands on the command line:
EDIT: use semicolon instead of colon to separate classpath elements in Windows environments
java -cp clojure.jar;classes;src clojure.main
Clojure 1.3.0
user=> (compile 'awesome)
This will produce the compiled classes into the classes folder. Please note that if your code depends on any library, you need to adapt the -cp parameter values when starting the JVM.
Than, you will create the JAR file using:
jar cvf awesome.jar -C classes .
Finally, to call your function:
java -cp clojure.jar;awesome.jar clojure.main -e "(use 'awesome) (life-universe-and-everything)"
I'd also advise you to read the official documentation.
9 Comments
clojure.main, which starts a REPL. java simply didn't know what to do after loading the classpath..-C dir tells jar that dir is the base path for its operations. In our case, it's first looking at classes then resolving . to be that folder, hence including all of its content into the JAR.
javatool has different syntax for setting the classpath. I'll update my post.