Hello! I'm trying to build a native image from a jar file inside a container but with mixed success; I'm stuck at this problem now where I can't even run the binary after successfully compiled it -
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.io.FileNotFoundException: Could not locate clojure/core/server__init.class, clojure/core/server.clj or clojure/core/server.cljc on classpath.
My Dockerfile:
FROM
...
RUN native-image \
-jar core-0.1.0-SNAPSHOT.jar \
--no-fallback \
--no-server \
--verbose \
--enable-url-protocols=http,https \
--report-unsupported-elements-at-runtime \
--initialize-at-run-time=com.taoensso.faraday,org.httpkit.client \
--initialize-at-build-time=clojure,org.httpkit,cheshire.core \
the-jar
I've been trying to mix and match the different classes to initialise at build and runtime without any real success.
Any tips would be extremely helpful 🙂@hallstrom.eric Use https://github.com/clj-easy/graal-build-time :)
Yeah I will probably try it, this is quite frustrating! Would be nice to figure out why it's broken though
it's not broken
it's just a result of clojure doing dynamic things. if you initialize clojure itself at build time it will work
which is what graal-build-time does for you
Using clj-easy leads to another error at buildtime -
#11 22.27 Error: Classes that should be initialized at run time got initialized during image building:
#11 22.27 com.fasterxml.jackson.core.io.SerializedString was unintentionally initialized at build time.
I'm using cheshire I guess that is the one causing it, adding it to --initialize-at-run-time= does not solve the issue either 😕Just add --initialize-at-build-time=com.faster.xml as well
Here is a project with example config: https://github.com/clj-easy/graal-config/blob/master/config/cheshire/cheshire/resources/META-INF/native-image/cheshire/cheshire/native-image.properties
Still the same issue -
11 24.56 com.fasterxml.jackson.core.JsonGenerator was unintentionally initialized at build time. To see why com.fasterxml.jackson.core.JsonGenerator got initialized use --trace-class-initialization=com.fasterxml.jackson.core.JsonGenerator
I made a typo: com.fasterxml without the dot
aaaahh finally, you are the best!