graalvm

octahedrion 2024-07-03T14:55:47.639569Z

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

octahedrion 2024-07-04T09:30:23.630549Z

thanks, I'll read up on that. What does liberica do that GraalVM doesn't ?

octahedrion 2024-07-04T12:27:33.880659Z

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
phronmophobic 2024-07-04T16:38:45.089259Z

Awesome!

phronmophobic 2024-07-04T16:39:27.446369Z

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.

zachcp 2025-01-10T18:02:42.958379Z

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

phronmophobic 2024-07-03T20:33:19.486019Z

Yes, I created a simple example at https://github.com/phronmophobic/membrane-native-image.

phronmophobic 2024-07-03T20:34:26.294869Z

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.

phronmophobic 2024-07-03T20:35:33.306999Z

The steps use liberica, https://bell-sw.com/liberica-native-image-kit/, but my notes indicate that graalvm should work on linux.

phronmophobic 2024-07-03T20:36:31.685709Z

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.

phronmophobic 2024-07-03T20:38:54.455189Z

I think I used the https://github.com/phronmophobic/membrane-native-image/blob/main/config.sh? I wish I had taken better notes.