This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-26
Channels
- # babashka (12)
- # beginners (53)
- # cider (6)
- # clj-kondo (2)
- # cljdoc (18)
- # clojars (6)
- # clojure (72)
- # clojure-europe (27)
- # clojurescript (85)
- # component (2)
- # conjure (4)
- # datalevin (43)
- # graalvm (8)
- # hyperfiddle (17)
- # lsp (72)
- # malli (5)
- # off-topic (1)
- # pathom (6)
- # perun (6)
- # polylith (10)
- # releases (1)
- # shadow-cljs (30)
- # xtdb (10)
Hi guys, I’m having trouble running a native-image with pedestal + jetty
. When I attempt to run the native image, I get this:
12:21:31.771 [main] DEBUG o.e.j.u.component.ContainerLifeCycle - QueuedThreadPool[qtp346120525]@14a1614d{STOPPED,8<=0<=50,i=0,r=-1,q=0}[NO_TRY] added {org.eclipse.jetty.util.thread.ThreadPoolBudget@54b93a35,POJO}
Exception in thread "main" java.lang.IllegalArgumentException: No matching ctor found for class org.eclipse.jetty.server.Server
at clojure.lang.Reflector.invokeConstructor(Reflector.java:288)
at io.pedestal.http.jetty$create_server.invokeStatic(jetty.clj:170)
at io.pedestal.http.jetty$create_server.invoke(jetty.clj:158)
at io.pedestal.http.jetty$server.invokeStatic(jetty.clj:232)
at io.pedestal.http.jetty$server.invoke(jetty.clj:229)
at clojure.lang.Var.invoke(Var.java:388)
at io.pedestal.http$server.invokeStatic(http.clj:348)
at io.pedestal.http$server.invoke(http.clj:335)
at io.pedestal.http$create_server.invokeStatic(http.clj:377)
at io.pedestal.http$create_server.invoke(http.clj:357)
at io.pedestal.http$create_server.invokeStatic(http.clj:374)
...
but works completely fine when I run the uberjar equivalent (e.g. java -jar ./target/api-0.1.0-SNAPSHOT-standalone.jar
). Note that I’ve included
[io.pedestal.http.jetty]
[io.pedestal.http.jetty.container]
in my requires. Happy to make a repro project if neededIt seems there is some reflection going on in pedestal. You can solve this by fixing those reflections or adding a reflection config. See graal docs
The reflection is happening here: https://github.com/pedestal/pedestal/blob/318d3b57bc5c60ff15aab7f9aea0214ea1113f77/jetty/src/io/pedestal/http/jetty.clj#L171 you can fix this with a type hint (contributing to pedestal) or by adding a reflection config: https://github.com/clj-easy/graal-docs The first one is preferred, but the second one is a short-term short-cut for you
Thanks for that! I went with using a reflection config. Making a native image went fine but the server doesnt seem to start properly. Will share details tomorrow
This may also help: https://github.com/clj-easy/graalvm-clojure/tree/master/pedestal
This project uses pedestal and generate a native-image binary as output https://github.com/moclojer/moclojer can be a good realworld reference 🙂