0

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

3
  • @skuro. I am getting this output on "java -cp clojure.jar:classes:src".Please help! as visible-> test-Clojure contains classes, src directory, src directory contains example.clj file. test-Clojure directory contains clojure.jar. output- > D:\work\test-Clojure>java -cp clojure.jar:classes:src Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) Commented Oct 5, 2011 at 10:03
  • Seems like the win32 version of the java tool has different syntax for setting the classpath. I'll update my post. Commented Oct 5, 2011 at 10:07
  • D:\work\test-Clojure>java -cp clojure.jar;classes;src Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) Commented Oct 5, 2011 at 10:40

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

9 Comments

I am getting this output on "java -cp clojure.jar:classes:src".Please help! as visible-> test-Clojure contains classes, src directory, src directory contains example.clj file. test-Clojure directory contains clojure.jar. output- > D:\work\test-Clojure>java -cp clojure.jar:classes:src Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file)
/sathya D:\work\test-Clojure>java -cp clojure.jar;classes;src Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file) **i am gettingthis output. cmd is askingto include some of these options! Its not working!!
I'm sorry, cut'n'paste issue here. I forgot to include the class you need to invoke, clojure.main, which starts a REPL. java simply didn't know what to do after loading the classpath..
i am getting 3 class files in classes directory. Is it fine? what does -C means while creating jar file.
Yes, you're effectively compiling your Clojure code. -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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.