Skip to content

Commit

Permalink
chore: update library loading to include an additional last resort th…
Browse files Browse the repository at this point in the history
…at uses System.loadLibrary
  • Loading branch information
kkriske committed Jul 24, 2023
1 parent 245529a commit d233e56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/org/sqlite/SQLiteJDBCLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,17 @@ private static boolean loadNativeLibrary(String path, String name) {
}
}

private static boolean loadNativeLibraryJdk() {
try {
System.loadLibrary(LibraryLoaderUtil.NATIVE_LIB_BASE_NAME);
return true;
} catch (UnsatisfiedLinkError e) {
System.err.println("Failed to load native library through System.loadLibrary");
e.printStackTrace();
return false;
}
}

/**
* Loads SQLite native library using given path and name of the library.
*
Expand Down Expand Up @@ -358,6 +369,12 @@ private static void loadSQLiteNativeLibrary() throws Exception {
}
}

// As an ultimate last resort, try loading through System.loadLibrary
if (loadNativeLibraryJdk()) {
extracted = true;
return;
}

extracted = false;
throw new Exception(
String.format(
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/sqlite/util/LibraryLoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.sqlite.SQLiteJDBCLoader;

public class LibraryLoaderUtil {

public static final String NATIVE_LIB_BASE_NAME = "sqlitejdbc";

/**
* Get the OS-specific resource directory within the jar, where the relevant sqlitejdbc native
* library is located.
Expand All @@ -15,7 +18,7 @@ public static String getNativeLibResourcePath() {

/** Get the OS-specific name of the sqlitejdbc native library. */
public static String getNativeLibName() {
return System.mapLibraryName("sqlitejdbc");
return System.mapLibraryName(NATIVE_LIB_BASE_NAME);
}

public static boolean hasNativeLib(String path, String libraryName) {
Expand Down

0 comments on commit d233e56

Please sign in to comment.