graalvm

Erkan 2022-04-09T11:48:28.774229Z

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 🙂

borkdude 2022-04-09T12:07:47.992119Z

@hallstrom.eric Use https://github.com/clj-easy/graal-build-time :)

Erkan 2022-04-09T12:13:34.183219Z

Yeah I will probably try it, this is quite frustrating! Would be nice to figure out why it's broken though

borkdude 2022-04-09T12:22:48.377729Z

it's not broken

borkdude 2022-04-09T12:24:32.023319Z

it's just a result of clojure doing dynamic things. if you initialize clojure itself at build time it will work

borkdude 2022-04-09T12:24:35.641079Z

which is what graal-build-time does for you

👍 1
Erkan 2022-04-09T18:14:02.531139Z

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 😕

borkdude 2022-04-09T18:39:35.064939Z

Just add --initialize-at-build-time=com.faster.xml as well

Erkan 2022-04-09T18:56:56.177109Z

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

borkdude 2022-04-09T18:57:32.885429Z

I made a typo: com.fasterxml without the dot

Erkan 2022-04-09T19:17:50.054319Z

aaaahh finally, you are the best!