Exception when trying to deploy as a jar (jetty)

408 views
Skip to first unread message

John Gabriele

unread,
Feb 2, 2017, 12:21:10 PM2/2/17
to Compojure
I just created a new little webapp:

    lein new compojure little-webapp

I can run it via `lein ring server-headless` during testing, but now want to change it so that I can deploy and run it as a jar.

I've followed the steps outlined at <http://clojure-doc.org/articles/tutorials/basic_web_development.html#deploy-your-webapp>, but when I try to do `lein uberjar` I get an exception:

Exception in thread "main" java.io.FileNotFoundException: Could not locate ring/core/protocols__init.class or ring/core/protocols.clj on classpath., compiling:(ring/util/servlet.clj:1:1)

My project.clj looks like this:

~~~
(defproject little-webapp "0.1.0"
  :description "A little webapp"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [compojure "1.5.2"]
                 [hiccup "1.0.5"]
                 [org.clojure/java.jdbc "0.7.0-alpha1"]
                 [org.xerial/sqlite-jdbc "3.16.1"]
                 [ring/ring-jetty-adapter "1.6.0-beta7"]
                 [ring/ring-defaults "0.2.2"]]
  :plugins [[lein-ring "0.9.7"]]
  :ring {:handler little-webapp.handler/app}
  :main little-webapp.handler
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.0"]]}})
~~~

`lein ancient` tells me all my dependencies are up to date.

This is with:

    $ lein version
    Leiningen 2.7.1 on Java 1.8.0_121 OpenJDK 64-Bit Server VM

Thanks!

James Reeves

unread,
Feb 2, 2017, 12:27:50 PM2/2/17
to Compojure
When you're using "lein-ring", you generally want to use the command:

  lein ring uberjar

As that creates the -main method for you, unlike "lein uberjar", which expects it to already exist.

You also have a dependency conflict. If you run "lein deps :tree" you can see the problem:

  Possibly confusing dependencies found:
  [compojure "1.5.2"] -> [ring/ring-core "1.5.1"]
   overrides
  [ring/ring-jetty-adapter "1.6.0-beta7"] -> [ring/ring-servlet "1.6.0-beta7"] -> [ring/ring-core "1.6.0-beta7"]
   and
  [ring/ring-jetty-adapter "1.6.0-beta7"] -> [ring/ring-core "1.6.0-beta7"]

So Compojure 1.5.2 expects to use Ring 1.5.1, but the Ring Jetty adapter is from Ring 1.6.0-beta7. You need to either use Ring 1.5.1 throughout, or upgrade Compojure and Ring-Defaults to the latest beta versions as well.

- James

--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+unsubscribe@googlegroups.com.
To post to this group, send email to comp...@googlegroups.com.
Visit this group at https://groups.google.com/group/compojure.
For more options, visit https://groups.google.com/d/optout.

John Gabriele

unread,
Feb 2, 2017, 12:39:13 PM2/2/17
to Compojure, ja...@booleanknot.com
Thanks, James! Ah, didn't realize I could use `lein ring uberjar`. Will get back that in a moment.

Meantime, after posting, I dug around some more and added `[ring/ring-core "1.6.0-beta7"]` to my project.clj :dependencies, and it then worked (I was able to build and run the jar). I don't see the dependency conflict though --- my deps :tree looks like:

~~~
$ lein deps :tree

 [clojure-complete "0.2.4" :exclusions [[org.clojure/clojure]]]
 [compojure "1.5.2"]
   [clout "2.1.2"]
     [instaparse "1.4.0" :exclusions [[org.clojure/clojure]]]
   [medley "0.8.2"]
   [org.clojure/tools.macro "0.1.5"]
   [ring/ring-codec "1.0.1"]
     [commons-codec "1.6"]
 [hiccup "1.0.5"]
 [javax.servlet/servlet-api "2.5" :scope "test"]
 [org.clojure/clojure "1.8.0"]
 [org.clojure/java.jdbc "0.7.0-alpha1"]
 [org.clojure/tools.nrepl "0.2.12" :exclusions [[org.clojure/clojure]]]
 [org.xerial/sqlite-jdbc "3.16.1"]
 [ring/ring-core "1.6.0-beta7"]
   [clj-time "0.11.0"]
     [joda-time "2.8.2"]
   [commons-fileupload "1.3.2"]
   [commons-io "2.5"]
   [crypto-equality "1.0.0"]
   [crypto-random "1.2.0"]
 [ring/ring-defaults "0.2.2"]
   [ring/ring-anti-forgery "1.0.1"]
   [ring/ring-headers "0.2.0"]
   [ring/ring-ssl "0.2.1"]
 [ring/ring-jetty-adapter "1.6.0-beta7"]
   [org.eclipse.jetty/jetty-server "9.2.17.v20160517"]
     [javax.servlet/javax.servlet-api "3.1.0"]
     [org.eclipse.jetty/jetty-http "9.2.17.v20160517"]
       [org.eclipse.jetty/jetty-util "9.2.17.v20160517"]
     [org.eclipse.jetty/jetty-io "9.2.17.v20160517"]
   [ring/ring-servlet "1.6.0-beta7"]
 [ring/ring-mock "0.3.0" :scope "test"]
~~~

That appears to me to indicate that compojure 1.5.2 doesn't depend upon ring/ring-core at all (which is listed separately further down). I also don't see ring/ring-jetty-adapter depending upon ring/ring-core... Maybe I'm reading the lein deps :tree output wrong?

-- John
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.

John Gabriele

unread,
Feb 2, 2017, 12:51:53 PM2/2/17
to Compojure, ja...@booleanknot.com
On Thursday, February 2, 2017 at 12:27:50 PM UTC-5, James Reeves wrote:
When you're using "lein-ring", you generally want to use the command:

  lein ring uberjar


Wow, nice! That works great, and with no changes required to a default compojure project!

Thanks!
-- John

James Reeves

unread,
Feb 2, 2017, 12:53:11 PM2/2/17
to Compojure
The dependency tree doesn't show any conflicts because you've effectively overridden them by adding in the ring-core dependency. Compojure is saying "I want ring-core 1.5.1", and the Jetty adapter is saying "I want ring-core 1.6.0-beta7", and you've resolved that conflict by adding in an explicit dependency for ring-core 1.6.0-beta7.

Compojure 1.5.2 will work with synchronous handlers, as will Ring-Defaults 0.2.2. But if you want to use asynchronous handlers, you need to use Compojure 1.6.0-beta3, and Ring-Defaults 0.3.0-beta2.

- James

To unsubscribe from this group and stop receiving emails from it, send an email to compojure+unsubscribe@googlegroups.com.

John Gabriele

unread,
Feb 2, 2017, 1:40:26 PM2/2/17
to Compojure, ja...@booleanknot.com
Ah. Thanks! I see what you mean.

Also, I found it instructive to change my project's dependencies, then check how the output of `lein deps :tree` changes.

--- John
Reply all
Reply to author
Forward
0 new messages