UnsatisfiedLinkError: No awt in java.library.path
Describe the issue Note: This is a reproduction of issue #2842 , as requested by @vjovanov. That issue had been marked as complete, but many users (including I) have continued to experience it -- so, vjovanov said: "to get this fixed it would be best to open a new ticket for this problem with a minimal reproducer".
Essentially, when attempting to load a class from the awt library in a native image, the titular exception occurs.
Steps to reproduce the issue
- Please check out the following project for a small, single-class repro of this error: reproduce-awt-lib-error-graal
- Run mvn clean install in the root directory of the project to build the jar
- Run mvn -Pnative package to build the native image, called test/repro-awt-lib-error
- Run docker run test/repro-awt-lib-error
Describe GraalVM and your environment:
- GraalVM version 23.0.2 (as determined by buildpack)
- JDK major version: 17
- OS: MacOS Sonoma 14.2.1
- Architecture: 6-Core Intel Core i9
- Maven version: 3.9.6
- Docker version: 24.0.7
More details The output printed from my enviroment, finishing with the error stack trace, is as follows:
docker run test/repro-awt-lib-error:latest
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.1.0)
2024-01-29T16:02:51.618Z INFO 1 --- [ main] org.example.App : Starting AOT-processed App using Java 17.0.9 with PID 1 (/workspace/org.example.App started by cnb in /workspace)
2024-01-29T16:02:51.619Z INFO 1 --- [ main] org.example.App : No active profile set, falling back to 1 default profile: "default"
2024-01-29T16:02:51.625Z INFO 1 --- [ main] org.example.App : Started App in 0.014 seconds (process running for 0.017)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no awt in java.library.path
at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:136)
at [email protected]/java.lang.ClassLoader.loadLibrary(ClassLoader.java:50)
at [email protected]/java.lang.Runtime.loadLibrary0(Runtime.java:818)
at [email protected]/java.lang.System.loadLibrary(System.java:1989)
at [email protected]/java.awt.image.ColorModel$1.run(ColorModel.java:210)
at [email protected]/java.awt.image.ColorModel$1.run(ColorModel.java:208)
at [email protected]/java.security.AccessController.executePrivileged(AccessController.java:173)
at [email protected]/java.security.AccessController.doPrivileged(AccessController.java:318)
at [email protected]/java.awt.image.ColorModel.loadLibraries(ColorModel.java:207)
at [email protected]/java.awt.image.ColorModel.<clinit>(ColorModel.java:220)
at [email protected]/java.awt.image.Raster.<clinit>(Raster.java:172)
at org.apache.pdfbox.pdmodel.PDDocument.<clinit>(PDDocument.java:107)
at org.example.App.main(App.java:17)
Thank you greatly for the concise reproducer! Assigning it to @pejovica as he is providing support for AWT.
@tabiStein Is libawt.so next to the built executable? If not, was it listed in the build output as a produced artifact?
@pejovica No, the executable is alone in a workspace/ directory.
Yes, I do see libawt.so listed in the built artifacts: [INFO] [creator] Produced artifacts: [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt_headless.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt_xawt.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libfontmanager.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libfreetype.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjava.so (jdk_library_shim) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjavajpeg.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjvm.so (jdk_library_shim) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/liblcms.so (jdk_library) [INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/org.example.App (executable)
I've attached the full output of running mvn -Pnative package, so you can check it in detail: packageOutput.txt
No, the executable is alone in a workspace/ directory.
Well, that's the problem. All produced artifacts are necessary for the executable to work (i.e., it can't work without the listed shared libraries).
Since the build output shows that all required artifacts are produced, and the error corresponds to the fact that the shared libraries are indeed missing when running the executable, there is nothing to fix on the native image side.
I'm guessing this is a bug with what drives the native-image as it doesn't seem to take into account all the artifacts produced by the build.
Thanks for the insight @pejovica , I have created a new issue with the Paketo team to see if it's an issue with their buildpack. Paketo Issue 427
If it's alright with you, I would like to keep this issue open until we can identify and verify the fix.
@tabiStein sure, I hope you don't mind that I've re-assigned the ticket to you. Please update the ticket when https://github.com/paketo-buildpacks/native-image/issues/308 is resolved.