Trying to make an uberjar

471 views
Skip to first unread message

Cecil Westerhof

unread,
Mar 4, 2017, 1:11:39 AM3/4/17
to clo...@googlegroups.com
Until now I can run my project without a problem with:
    lein trampoline run &

But I was told that I should use an uberjar.

My project.clj was:
(defproject quotes "0.0.1"
  :description "Initial quotes application"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure            "1.8.0"]
                 [clj-time                       "0.12.0"]
                 [com.h2database/h2              "1.3.176"]
                 [instaparse                     "1.4.2"]
                 [org.clojure/math.numeric-tower "0.0.4"]
                 [seesaw                         "1.4.5"]
                 [yesql                          "0.5.3"]]
  :main quotes.core
  :jvm-opts ["-Xmx320m"]
)

That did not work. So I changed it to:
(defproject quotes "0.0.1"
  :description "Initial quotes application"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure            "1.8.0"]
                 [clj-time                       "0.12.0"]
                 [com.h2database/h2              "1.3.176"]
                 [instaparse                     "1.4.2"]
                 [org.clojure/math.numeric-tower "0.0.4"]
                 [seesaw                         "1.4.5"]
                 [yesql                          "0.5.3"]]
  :main quotes.core
  :aot [quotes.core]
  :profiles {
    :uberjar {:aot :all}
  }
  :jvm-opts ["-Xmx320m"]
)

But when running:
    lein uberjar
I still get:
This code is executed when starting Clojure.
Compiling quotes.core
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method, or the namespace has not been AOT-compiled.
Created /home/cecil/Clojure/Quotes/target/quotes-0.0.1.jar
Created /home/cecil/Clojure/Quotes/target/quotes-0.0.1-standalone.jar

What do I need to change to make an uberjar. (Jars are generated, but cannot be used.)

--
Cecil Westerhof

Jeaye

unread,
Mar 4, 2017, 1:45:02 AM3/4/17
to clo...@googlegroups.com
Cecil,

> But when running:
> lein uberjar
> I still get:
> This code is executed when starting Clojure.
> Compiling quotes.core
> Warning: The Main-Class specified does not exist within the jar. It may not
> be executable as expected. A gen-class directive may be missing in the
> namespace which contains the main method, or the namespace has not been
> AOT-compiled.
> Created /home/cecil/Clojure/Quotes/target/quotes-0.0.1.jar
> Created /home/cecil/Clojure/Quotes/target/quotes-0.0.1-standalone.jar
>
> What do I need to change to make an uberjar. (Jars are generated, but
> cannot be used.)

The warning which lein provided is trying to tell you exactly what you need to do. In the `ns` form of your quotes.core namespace, you should add a (:gen-class). Example:

```clojure
(ns quotes.core
(:gen-class))
```

Cheers,
Jeaye
signature.asc

Cecil Westerhof

unread,
Mar 4, 2017, 2:09:55 AM3/4/17
to clo...@googlegroups.com

​That was what was needed. Thanks.

And I could remove the added:
:profiles {
    :uberjar {:aot :all}
  }

--
Cecil Westerhof

Jeaye

unread,
Mar 4, 2017, 2:14:12 AM3/4/17
to clo...@googlegroups.com
For the best performance, you likely want AOT (ahead-of-time) compilation. In general, I'd recommend keeping that uberjar profile with `{:aot :all}`.
signature.asc

Cecil Westerhof

unread,
Mar 4, 2017, 8:44:39 AM3/4/17
to clo...@googlegroups.com

​That is why it is smart to communicate small non essential changes: people can set you on the right track. :-)

I put that back. I now removed the ‘:aot [quotes.core]’, or should I keep that also?

When I first got the error I found two different pieces of advice. One for both changes. When those did not work I asked here.


I should pick up Clojure again. I only did one little project (long ago) to try it out. But that is no way to learn a language. Sadly there is no real use here for it. :'-(

--
Cecil Westerhof

Jeaye

unread,
Mar 4, 2017, 3:15:32 PM3/4/17
to clo...@googlegroups.com
There's no need for `:aot [quotes.core]` if you're using `:aot :all` in your uberjar profile. The only other reason you'd want it is to AOT that namespace outside of the uberjar profile. That's up to you, but typically not a concern.
signature.asc

Cecil Westerhof

unread,
Mar 4, 2017, 4:01:53 PM3/4/17
to clo...@googlegroups.com
2017-03-04 21:15 GMT+01:00 Jeaye <con...@jeaye.com>:
> > > ​That was what was needed. Thanks.
> > >
> > > And I could remove the added:
> > > :profiles {
> > >     :uberjar {:aot :all}
> > >   }
> >
> > For the best performance, you likely want AOT (ahead-of-time) compilation.
> > In general, I'd recommend keeping that uberjar profile with `{:aot :all}`.
> >
>
> ​That is why it is smart to communicate small non essential changes: people
> can set you on the right track. :-)
>
> I put that back. I now removed the ‘:aot [quotes.core]’, or should I keep
> that also?

There's no need for `:aot [quotes.core]` if you're using `:aot :all` in your uberjar profile. The only other reason you'd want it is to AOT that namespace outside of the uberjar profile. That's up to you, but typically not a concern.

​Thank you. I thought so, but it is better to be sure.

--
Cecil Westerhof
Reply all
Reply to author
Forward
0 new messages