Fork me on GitHub
#graalvm
<
2023-03-26
>
anonimitoraf01:03:35

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 needed

borkdude06:03:28

It 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

borkdude06:03:53

Also see link in description of this channel

borkdude09:03:57

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

anonimitoraf10:03:52

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

anonimitoraf10:03:34

Yep I checked that out too

👍 2
souenzzo10:03:18

This project uses pedestal and generate a native-image binary as output https://github.com/moclojer/moclojer can be a good realworld reference 🙂