graal
graal copied to clipboard
[GR-52267] Can't compile with Onnxruntime library, conflict with svm-enterprise.jar
I worked on a shared library, which uses onnxruntime for inference. When I use native-image -jar ./target/test-1.0-SNAPSHOT-jar-with-dependencies.jar --shared -H:Name=libtest to generate shared library, i get the following error:
Error: Class-path entry file:///xxx/target/test-1.0-SNAPSHOT-jar-with-dependencies.jar contains class ai.onnxruntime.ValueInfo. This class is part of the image builder itself (in file:///xxx/graalvm-jdk-21.0.1+12.1/Contents/Home/lib/svm/builder/svm-enterprise.jar) and must not be passed via -cp. This can be caused by a fat-jar that illegally includes svm.jar (or graal-sdk.jar) due to its build-time dependency on it. As a workaround, -H:+AllowDeprecatedBuilderClassesOnImageClasspath allows turning this error into a warning. Note that this option is deprecated and will be removed in a future version.
When I added the '-H:+AllowDeprecatedBuilderClassesOnImageClasspath' parameter according to the instructions, I can have the shared library, but when use the shared library, it errors with:java.lang.NoClassDefFoundError: ai.onnxruntime.OrtEnvironment
Graal version: graalvm-jdk-21.0.1+12.1
Reproducible code attached: test.zip
run mvn package and then native-image -jar ./target/test-1.0-SNAPSHOT-jar-with-dependencies.jar --shared -H:Name=libtest
@oubidar-Abderrahim I have created new issue
Thanks for filing the ticket, @JiangWork. As the error correctly suggests, the Native Image builder also has a dependency on ai.onnxruntime. We are looking into a fix for this.
In my testing version "GraalVM CE 21.0.2+13.1" seems to not throw this error anymore
@zekronium Looks like it is community version? I am using enterprise version. Let me try "GraalVM CE 21.0.2+13.1"
@zekronium Looks like it is community version? I am using enterprise version. Let me try "GraalVM CE 21.0.2+13.1"
I was encountering the same exact issue with CE too
hi, @fniephaus. Just want to check, any plan to fix this issue?
Yes, we are working on a fix for this as we speak. We'll share an update as soon as it's ready.
@fniephaus any updates on this? I too am tripping on the same issue. This effectively prevents creation of a native image for AI applications using AllMiniLmL6V2EmbeddingModel because this class has a dependency on the onnxruntime jar.
@fniephaus any updates? Blocked building Confluence AI application native image.
Hi @sjivan and @bzivalje, a fix should ship with the new Oracle GraalVM for JDK 24 release. Please give this a try and let us know if anything isn't working for you. Closing this ticket for now, we can reopen if there's still an issue.
@fniephaus I am getting
java.lang.UnsatisfiedLinkError: Can't load library: onnxruntime | java.library.path = [.]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibraries.loadLibraryRelative(NativeLibraries.java:141)
at java.base@24/java.lang.ClassLoader.loadLibrary(ClassLoader.java:100)
at java.base@24/java.lang.Runtime.loadLibrary0(Runtime.java:822)
at java.base@24/java.lang.System.loadLibrary(System.java:1663)
at ai.onnxruntime.OnnxRuntime.load(OnnxRuntime.java:375)
at ai.onnxruntime.OnnxRuntime.init(OnnxRuntime.java:160)
at ai.onnxruntime.OrtEnvironment.<clinit>(OrtEnvironment.java:31)
at dev.langchain4j.model.embedding.OnnxBertBiEncoder.<init>(OnnxBertBiEncoder.java:38)
at dev.langchain4j.model.embedding.AbstractInProcessEmbeddingModel.loadFromJar(AbstractInProcessEmbeddingModel.java:21)
at dev.langchain4j.model.embedding.AllMiniLmL6V2EmbeddingModel.<clinit>(AllMiniLmL6V2EmbeddingModel.java:18)
at com.scs.urulecopilot.v2.ConfluenceAI.<clinit>(ConfluenceAI.java:39)
at com.scs.urulecopilotcli.AIConsoleCommand.jline3(AIConsoleCommand.java:406)
at com.scs.urulecopilotcli.AIConsoleCommand.run(AIConsoleCommand.java:194)
at com.scs.urulecopilotcli.Main.main(Main.java:101)
at java.base@24/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)
Thanks for the update, @bzivalje. I've reopened the ticket and we'll look into this again (tracked internally via GR-63517).
@fniephaus My bad. Did not realize graalvm 24 handles metadata differently than teh version 23. Now using class path to read reachability metadata. The Onnxruntime is now found. As far as I am concerned you can ditch this issue.
Thanks for your help,
Bosko
I'm still getting the same "can't load library" error at runtime. @bzivalje could you share your workaround?
Graalvm 24 fixed it for me.  Make sure you are on that version. Sent from my iPhoneOn May 8, 2025, at 6:47 AM, Alex Merritt @.***> wrote: EmergentOrder left a comment (oracle/graal#8431) I'm still getting the same "can't load library" error at runtime. @bzivalje could you share your workaround?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>
I am using graalvm 24. What did you mean by this: "Now using class path to read reachability metadata" ?
Ah yes.  In graalvm 24 you have to put the reachability json file on your class path.  I stored mine in the jar under META-INF.  Please check ref manual for version 24. Sent from my iPhoneOn May 8, 2025, at 9:31 AM, Alex Merritt @.***> wrote: EmergentOrder left a comment (oracle/graal#8431) I am using graalvm 24. What did you mean by this: "Now using class path to read reachability metadata" ?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>