Build uberjar for Pedestal service

237 views
Skip to first unread message

ja...@knowledgetree.com

unread,
Nov 20, 2013, 11:39:21 AM11/20/13
to pedesta...@googlegroups.com, Rob Chekaluk, Peter Garbers
Hi folks,

We're attempting to build a .jar for a pedestal app, but are missing a piece somewhere along the line.

The project.clj is below along with the error produced when attempting to run the jar. Seems like there's a classpath problem or something similar, but I'm not sure.

Any help would be greatly appreciated.

Thanks,
James


Run: lein uberjar
Result: Creates jars in target/ directory.

Run: java -jar target/myproject-0.0.1-standalone.jar
Result:
Exception in thread "main" java.lang.NoClassDefFoundError: myproject/server
Caused by: java.lang.ClassNotFoundException: myproject.server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202
...

project.clj (parts redacted):
---
(defproject myproject "0.0.1-SNAPSHOT"
:description ""
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]
[io.pedestal/pedestal.service "0.2.2"]
[io.pedestal/pedestal.service-tools "0.2.2"]

;; auto-reload changes
[ns-tracker "0.2.1"]

;; DB
[com.datomic/datomic-free "0.8.4159" :exclusions [org.slf4j/slf4j-nop]]

;; Logging
[ch.qos.logback/logback-classic "1.0.7" :exclusions [org.slf4j/slf4j-api]]
[org.slf4j/jul-to-slf4j "1.7.2"]
[org.slf4j/jcl-over-slf4j "1.7.2"]
[org.slf4j/log4j-over-slf4j "1.7.2"]

;; Environment
[environ "0.4.0"]

;; Other
[camel-snake-kebab "0.1.2"]
[cheshire "5.2.0"]
[clj-http "0.7.7"]
[clj-time "0.6.0"]
[crypto-random "1.1.0"]
[de.ubercode.clostache/clostache "1.3.1"]
[pandect "0.3.0"]]
:profiles {:dev {:source-paths ["dev"]
:dependencies [;; Remove this line and uncomment the next line to
;; use Tomcat instead of Jetty:
[io.pedestal/pedestal.jetty "0.2.2"]
; [io.pedestal/pedestal.tomcat "0.2.2"]
]
:env {:application-environment "dev-local"}}}
:plugins [[ohpauleez/lein-pedestal "0.1.0-beta10"]
[lein-environ "0.4.0"]
[lein-shell "0.3.0"]]
:min-lein-version "2.0.0"
:resource-paths ["config", "resources", "vendor"]
:main ^{:skip-aot true} myproject.server)

myproject/server.clj:
---
(ns myproject.server
(:gen-class) ; for -main method in uberjar
(:require [io.pedestal.service-tools.dev :as dev]
[io.pedestal.service-tools.server :as server]
[myproject.service :as service]))

(defn run-dev
"The entry-point for 'lein run-dev'"
[& args]
(dev/init service/service #'service/routes)
(apply dev/-main args))

;; To implement your own server, copy io.pedestal.service-tools.server and
;; customize it.

(defn -main
"The entry-point for 'lein run'"
[& args]
(server/init service/service)
(apply server/-main args))

;; Fns for use with io.pedestal.servlet.ClojureVarServlet

(defn servlet-init [this config]
(server/init service/service)
(server/servlet-init this config))

(defn servlet-destroy [this]
(server/servlet-destroy this))

(defn servlet-service [this servlet-req servlet-resp]
(server/servlet-service this servlet-req servlet-resp))

roman....@burningswell.com

unread,
Nov 20, 2013, 12:18:51 PM11/20/13
to pedesta...@googlegroups.com, Rob Chekaluk, Peter Garbers, ja...@knowledgetree.com
I think you have to add this to your :profiles key in project.clj

:uberjar {:aot [myproject.server]}

The :skip-aot true annotation prevents compilation in dev mode.

ja...@knowledgetree.com

unread,
Nov 20, 2013, 12:42:19 PM11/20/13
to pedesta...@googlegroups.com, Rob Chekaluk, Peter Garbers, ja...@knowledgetree.com, roman....@burningswell.com
Thanks, Roman! Your response set me on the right path. I wasn't aware of the :uberjar profile.

I'm actually relying on the aot not to run, so I had to change your suggestion to the following, which works for me.

:uberjar {:main ^{:skip-aot true} [myproject.server]
:dependencies [[io.pedestal/pedestal.jetty "0.2.2"]]}

Thanks again,
James

Reply all
Reply to author
Forward
0 new messages