Jar produced with lane-uberjar fails in NoClassDefFoundError

I have a simple web application with this project.clj:

(defproject squirrel-money "1.0.0-SNAPSHOT" :description "Squirrel Money" :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"] [compojure "0.5.3"] [ring/ring-jetty-adapter "0.3.5"] [hiccup "0.3.1"] [postgresql "8.4-701.jdbc4"] [clj-time "0.2.0-SNAPSHOT"]] :dev-dependencies [[lein-eclipse "1.0.0"]] :main squirrel-money.main :repl-init-script "src/squirrel_money/init_repl.clj") 

My main thing is this:

 (ns squirrel-money.main (:gen-class) (:use [compojure.core] [ring.adapter.jetty]) (:require [compojure.route :as route] [squirrel-money.savings :as savings])) (defn launch [routedef] (run-jetty routedef {:port 17080})) (defroutes money-routes (GET "/savings" [] (savings/render)) (route/not-found "Page not found")) (defn -main [& args] (launch money-routes)) 

It works just fine with REPL. However, when I create a jar with lein uberjar and try to execute it as:

 java -jar squirrel-money-1.0.0-SNAPSHOT-standalone.jar 

He dies with this exception:

 Exception in thread "main" java.lang.NoClassDefFoundError: compojure/response/Renderable at squirrel_money.main$fn__1067.invoke(main.clj:18) at squirrel_money.main__init.load(Unknown Source) at squirrel_money.main__init.<clinit>(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at clojure.lang.RT.loadClassForName(RT.java:1578) at clojure.lang.RT.load(RT.java:399) at clojure.lang.RT.load(RT.java:381) at clojure.core$load$fn__4511.invoke(core.clj:4905) at clojure.core$load.doInvoke(core.clj:4904) at clojure.lang.RestFn.invoke(RestFn.java:409) at clojure.lang.Var.invoke(Var.java:365) at squirrel_money.main.<clinit>(Unknown Source) Caused by: java.lang.ClassNotFoundException: compojure.response.Renderable at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) ... 13 more 

What am I doing wrong? How to make it work?

Not sure if this is important, but I noticed that inside the jar my files, clojure and Java libs are unpacked as .class files, and all clojure libs are present only as simple .clj files.

+6
clojure leiningen compojure
source share
1 answer

This seems to be a leinigen 1.4.0 bug. You might want to try creating uberjar with leiningen 1.3.1.

Edit

Leiningen 1.4.0 deletes files without a .class project to work with the Clojure error (see CLJ-322 ). Apparently, this behavior can sometimes cause problems.

You can leave leiningen 1.4.0 by deleting files without a .class project by setting :keep-non-project-classes to true in project.clj .

For more information, see the leinigen related issue .

+2
source share

All Articles