Creating executable Jars?

7 views
Skip to first unread message

smarf

unread,
Jan 27, 2009, 11:01:22 PM1/27/09
to Clojure
(ns progs.comex.compileexample
(:gen-class))

(defn -main
[]
(println (str "Hello " "Sverker" "!")))

(binding [*compile-path* "C:\\clojure\\classes"]
(compile 'progs.comex.compileexample))


I compiled C:/clojure/progs/comex/compileexample.clj.
I can run the program with:

C:\clojure\classes>java -cp C:/clojure/clojure.jar;
progs.comex.compileexample
Hello Sverker!

Manifest.txt says:
Main-Class: compileexample.class

and is finished with a newline.

so how do I make it a jar?


C:\clojure\classes\progs\comex>dir
Volume in drive C is Vista
Volume Serial Number is DC46-FE33

Directory of C:\clojure\classes\progs\comex

2009-01-28 03:33 <DIR> .
2009-01-28 03:33 <DIR> ..
2009-01-27 23:47 1 101 compileexample$fn__554.class
2009-01-27 23:47 1 131 compileexample$_main__551.class
2009-01-27 23:47 1 812 compileexample.class
2009-01-27 23:47 2 431 compileexample__init.class
2009-01-28 03:31 34 manifest.txt
5 File(s) 6 509 bytes
2 Dir(s) 5 783 875 584 bytes free

C:\clojure\classes\progs\comex>jar cf Hmm.jar C:/clojure/clojure.jar
manifest.tx
t compileexample.class

C:\clojure\classes\progs\comex>Hmm.jar

C:\clojure\classes\progs\comex>


i get a popup :
Java Virtual Machine Launcher
Failed to load Main-class manifest attribute from
C:\clojure

.Bill Smith

unread,
Jan 28, 2009, 10:02:47 AM1/28/09
to Clojure
Your manifest assumes your main class lives in the default Java
package, but doesn't it really live in the progs.comex package? Also,
don't you need to use the "m" switch when you specify a manifest to
the jar command?

Bill

On Jan 27, 10:01 pm, smarf <haskell...@gmail.com> wrote:
> (ns progs.comex.compileexamples

Greg Harman

unread,
Jan 28, 2009, 10:06:56 AM1/28/09
to Clojure
A couple things:

1. I don't know about embedding jars... Instead, use the Class-Path
manifest attribute to link in clojure.jar.

2. I noticed that your jar command was specifically packaging only
compileexample.class. You need all 4 of those generated classes in the
jar.

-Greg

luciofulci

unread,
Jan 28, 2009, 4:34:53 PM1/28/09
to Clojure
That's how I managed to create jar:

I have folders c:\user\apps and c:\user\apps\classes (which can be
empty, but must exist) (beside clojure.jar and other jars) in
classpath.
I have a file:
c:\user\apps\my\hello.clj with this contents:

(ns my.hello
(:gen-class))

(defn -main [] (println "Hello World!"))

I launch repl from the dir c:\user\apps and enter this command:
(compile 'my.hello)
and I have my compiled classes in c:\user\apps\classes\my
I unpack clojure.jar to c:\user\classes and delete a META-INF folder.
Then in this folder (c:\user\classes) I create manifest.txt:
Main-Class: my.hello

which ends with a newline.

after that I execute this command in the same folder (c:\user
\classes):
jar cmf manifest.txt hello.jar clojure my

And there I have an executable jar.

so when I run java -jar hello.jar It prints out "Hello, world!".
That's it.

Well, I hope that helps...

Emeka

unread,
Jan 29, 2009, 6:43:31 AM1/29/09
to clo...@googlegroups.com

luciofulci

 I'm interested in your instruction, however, are c:\user\apps\classes and c:\user\classes the same thing?

Emeka


kkw

unread,
Feb 14, 2009, 6:52:29 PM2/14/09
to Clojure
Hi Emeka,

Did you have success in this?

Kev

Emeka

unread,
Feb 17, 2009, 7:09:19 AM2/17/09
to clo...@googlegroups.com
Kev,

I didn't make it, however, I guess the issue was on  namespace and not on the instruction given. I will try again and again until I get my head around namespace, or could you help me to jump start?

Emeka


kkw

unread,
Feb 18, 2009, 6:12:07 PM2/18/09
to Clojure
Hi Emeka,

Where Lucio says:

"after that I execute this command in the same folder (c:\user
\classes): "

I had success if I instead followed:

"after that I execute this command in the same folder (c:\user\apps
\classes): "

Adding the c:\user\apps\classes directory to your classpath is
mandatory, otherwise the (compile) step won't work. I saw another
thread where Rich advised creating a jar file with the .clj source
inside instead:

http://groups.google.com/group/clojure/browse_thread/thread/e45be60b8f7a4d16/356b1cf2a2701bbd?lnk=gst&q=compiling+clj+jar#356b1cf2a2701bbd

This sounds like the better way to go.

Kev

Emeka

unread,
Feb 19, 2009, 1:33:19 PM2/19/09
to clo...@googlegroups.com
Kev
Are you using ms windows?

Emeka


Reply all
Reply to author
Forward
0 new messages