Making a jar where the "main" class in manifest is from gen-class

7 views
Skip to first unread message

timshawn

unread,
Jun 19, 2009, 1:02:04 PM6/19/09
to Clojure
Hello clojure developers,
I had a question regarding jar-ring up clojure generated source using
gen-class.

When I do a gen-class, and say either :main is true, or add a -main
method, the class file that gets generated always has a random prefix.

I need to enter the Main class in a jar's Manifest, and was wondering
how you guys have done it.
Can I somehow control the name of the generated class of the main
function?
Or is there some other way?

Thanks,
Tim

Stephen C. Gilardi

unread,
Jun 19, 2009, 1:42:37 PM6/19/09
to clo...@googlegroups.com

On Jun 19, 2009, at 1:02 PM, timshawn wrote:

> Hello clojure developers,
> I had a question regarding jar-ring up clojure generated source using
> gen-class.
>
> When I do a gen-class, and say either :main is true, or add a -main
> method, the class file that gets generated always has a random prefix.

One important need filled by gen-class is exactly this case: you need
a class with a name you can specify completely and use elsewhere.

> I need to enter the Main class in a jar's Manifest, and was wondering
> how you guys have done it.

There's an example at clojure.contrib.repl_ln.clj. It uses just "(:gen-
class)" (no options) in its "ns" declaration:

(ns
...
clojure.contrib.repl-ln
(:gen-class)
...)

(defn- -main
"Main entry point, starts a repl enters the user
namespace and processes command line args."
[& args]
(repl :init
(fn []
(println "Clojure" (clojure-version))
(in-ns 'user)
(process-command-line args))))

(this could also have been defn rather than defn- and would behave the
same regarding being callable from Java)

When compiled, this produces the class file:

clojure/contrib/repl_ln.class

You can see it in clojure.contrib.jar (either using a tool that can
display its contents directly or bar unjarring it: jar xvf
clojure.contrib.jar)

If the example above doesn't lead you to a solution, please post more
particulars and a simplified example that shows the problem you're
seeing.

--Steve

Eric Willigers

unread,
Jun 19, 2009, 9:15:55 PM6/19/09
to Clojure
On Jun 20, 3:42 am, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> One important need filled by gen-class is exactly this case: you need  
> a class with a name you can specify completely and use elsewhere.
>
> > I need to enter the Main class in a jar's Manifest, and was wondering
> > how you guys have done it.
>
> There's an example at clojure.contrib.repl_ln.clj. It uses just "(:gen-
> class)" (no options) in its "ns" declaration:

There's also an example in the peepcode talk (costs $9)
http://peepcode.com/products/functional-programming-with-clojure

gen-class accepts
:name aname

timshawn

unread,
Jun 20, 2009, 6:09:42 PM6/20/09
to Clojure
Thanks! I was bitten by the underscore and dashes thing in the package
name/filesystem.
This example fortunately had that to show me the way to do it.
Thanks for your help.
>  smime.p7s
> 3KViewDownload
Reply all
Reply to author
Forward
0 new messages