Skip to content

Commit

Permalink
Linux: load jawt.so explicitly before loading FlatLaf native librar…
Browse files Browse the repository at this point in the history
…y to fix `UnsatisfiedLinkError: ... libjawt.so: cannot open shared object file ...` (issue #482)
  • Loading branch information
DevCharly committed Aug 20, 2022
1 parent fb4576f commit 0baae7d
Showing 1 changed file with 15 additions and 9 deletions.
Expand Up @@ -55,11 +55,25 @@ private static void initialize() {
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 <jdk>/bin/java.exe.
// When using <jdk>/jre/bin/java.exe, it is found.
// jawt.dll is located in <jdk>/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

Expand All @@ -81,14 +95,6 @@ private static NativeLibrary createNativeLibrary( String libraryName ) {
}

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 <jdk>/bin/java.exe.
// When using <jdk>/jre/bin/java.exe, it is found.
// jawt.dll is located in <jdk>/jre/bin/.
// Java 9 and later do not have this problem.
try {
System.loadLibrary( "jawt" );
} catch( UnsatisfiedLinkError ex ) {
Expand Down

0 comments on commit 0baae7d

Please sign in to comment.