Fork me on GitHub
#graalvm
<
2022-04-09
>
Erkan11:04:28

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 🙂

Erkan12:04:34

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

borkdude12:04:48

it's not broken

borkdude12:04:32

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

borkdude12:04:35

which is what graal-build-time does for you

👍 1
Erkan18:04:02

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 😕

borkdude18:04:35

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

Erkan18:04:56

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

borkdude18:04:32

I made a typo: com.fasterxml without the dot

Erkan19:04:50

aaaahh finally, you are the best!