has anyone been successful in getting AWT to work with native image ? I'm getting
java.lang.UnsatisfiedLinkError: Can't load library: awt | java.library.path = [/opt/graalvm-jdk-22+36.1/lib/, /usr/lib64, /lib64, /lib, /usr/lib]
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibraries.loadLibraryRelative(NativeLibraries.java:141)
at java.base@22/java.lang.ClassLoader.loadLibrary(ClassLoader.java:106)
at java.base@22/java.lang.Runtime.loadLibrary0(Runtime.java:916)
at java.base@22/java.lang.System.loadLibrary(System.java:2068)
at java.desktop@22/java.awt.image.ColorModel$1.run(ColorModel.java:211)
at java.desktop@22/java.awt.image.ColorModel$1.run(ColorModel.java:209)
at java.base@22/java.security.AccessController.executePrivileged(AccessController.java:128)
at java.base@22/java.security.AccessController.doPrivileged(AccessController.java:319)
at java.desktop@22/java.awt.image.ColorModel.loadLibraries(ColorModel.java:208)
at java.desktop@22/java.awt.image.ColorModel.<clinit>(ColorModel.java:221)...
in a docker container in which libawt.so etc are in /usr/lib or the same directory as the executablethanks, I'll read up on that. What does liberica do that GraalVM doesn't ?
ok I worked it out with GraalVM. What one needs to do is:
• run your code in the docker container you're going to use to build your native image with, using -agentlib:native-image-agent=config-output-dir=... to generate a jni-config.json
• use the above for -H:JNIConfigurationFiles=native-configuration/jni-config.json native image arg
• generate native image
• ensure that *.so files are copied into the same directory as the generated output
Awesome!
I think the AWT and Swing support is a little more experimental for graalvm. There are some other alternatives that focus more in those areas like gluon and liberica.
Hi @octo221 - I'm hitting the same issue and followed your advice but haven't been able to get my library to work. I wonder if my *.so files are not correct? But you know what. I think I'll try the Liberika suggestion. PR is here if you want to poke around. https://github.com/zachcp/cdk-cli/tree/2025010-native zcp
Yes, I created a simple example at https://github.com/phronmophobic/membrane-native-image.
It's been a while, so I don't remember the exact steps, but you can check the https://github.com/phronmophobic/membrane-native-image?tab=readme-ov-file#resources and https://github.com/phronmophobic/membrane-native-image/blob/main/.github/workflows/build-linux.yml.
The steps use liberica, https://bell-sw.com/liberica-native-image-kit/, but my notes indicate that graalvm should work on linux.
The https://github.com/phronmophobic/membrane-native-image/blob/main/compile.sh script references config, but I don't quite remember where I got the config from.
I think I used the https://github.com/phronmophobic/membrane-native-image/blob/main/config.sh? I wish I had taken better notes.