graalvm 2024-07-03

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 executable

thanks, 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

🎉 1

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

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.