From 0baae7da8b59f6e635841ccd71b5952f1746c20d Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sat, 20 Aug 2022 23:44:41 +0200 Subject: [PATCH] Linux: load `jawt.so` explicitly before loading FlatLaf native library to fix `UnsatisfiedLinkError: ... libjawt.so: cannot open shared object file ...` (issue #482) --- .../formdev/flatlaf/ui/FlatNativeLibrary.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLibrary.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLibrary.java index 3bfd3064..e486b7a8 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLibrary.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLibrary.java @@ -55,11 +55,25 @@ class FlatNativeLibrary libraryName += "_64"; // load jawt native library - loadJAWT(); + if( !SystemInfo.isJava_9_orLater ) { + // In Java 8, load jawt.dll (part of JRE) explicitly because it + // is not found when running application with /bin/java.exe. + // When using /jre/bin/java.exe, it is found. + // jawt.dll is located in /jre/bin/. + // Java 9 and later do not have this problem. + loadJAWT(); + } } else if( SystemInfo.isLinux && SystemInfo.isX86_64 ) { // Linux: requires x86_64 libraryName = "flatlaf-linux-x86_64"; + + // Load jawt.so (part of JRE) explicitly because it is not found + // in all Java versions/distributions. + // E.g. not found in Java 13 and later from openjdk.java.net. + // There seems to be also differences between distributions. + // E.g. Adoptium Java 17 does not need this, but Java 17 from openjdk.java.net does. + loadJAWT(); } else return; // no native library available for current OS or CPU architecture @@ -81,14 +95,6 @@ class FlatNativeLibrary } private static void loadJAWT() { - if( SystemInfo.isJava_9_orLater ) - return; - - // In Java 8, load jawt.dll (part of JRE) explicitly because it - // is not found when running application with /bin/java.exe. - // When using /jre/bin/java.exe, it is found. - // jawt.dll is located in /jre/bin/. - // Java 9 and later do not have this problem. try { System.loadLibrary( "jawt" ); } catch( UnsatisfiedLinkError ex ) {