Skip to content

Conversation

@staticlibs
Copy link
Collaborator

This is a backport of the PR #450 to v1.4-andium stable branch.

This PR is a continuation of #447 PR to allow using duckdb_jdbc-x.x.x.x-nolib.jar along with a JNI native library, that is loaded directly from file system.

It extends the idea from #421 (and supersedes it) implementing the following logic:

  1. if the driver JAR has a bundled native library (for current JVM os/arch), then this library will be unpacked to the temporary directory and loaded from there. If the library cannot be unpacked or loaded - there is no fallback to other methods (it is expected that -nolib JAR is used for other loading methods)

  2. if the driver JAR does not hava a native library bundled inside it, then it will try to load it with:

System.loadLibrary("duckdb_java");

This call will search the library in java.library.path (using a platform-specific file name like duckdb_java.dll) or will use other methods defined by the host application.

  1. if the native library cannot be loaded by name, then the driver will check whether a file with the DuckDB internal naming (like libduckdb_java.so_linux_amd64) exists in file system next to the driver JAR (in the same directory). If the library file is found there - then the driver will attempt to load it as the last resort.

Testing: new test added that covers loading from the same dir and loading by name.

Fixes: #444

This is a backport of the PR duckdb#450 to `v1.4-andium` stable branch.

This PR is a continuation of duckdb#447 PR to allow using
`duckdb_jdbc-x.x.x.x-nolib.jar` along with a JNI native library, that
is loaded directly from file system.

It extends the idea from duckdb#421 (and supersedes it) implementing the
following logic:

1. if the driver JAR has a bundled native library (for current JVM
   os/arch), then this library will be unpacked to the temporary
   directory and loaded from there. If the library cannot be unpacked or
   loaded - there is no fallback to other methods (it is expected that
   `-nolib` JAR is used for other loading methods)

2. if the driver JAR does not hava a native library bundled inside it,
   then it will try to load it with:

```java
System.loadLibrary("duckdb_java");
```

   This call will search the library in `java.library.path` (using a
   platform-specific file name like `duckdb_java.dll`) or will use other
   methods defined by the host application.

3. if the native library cannot be loaded by name, then the driver will
   check whether a file with the DuckDB internal naming (like
   `libduckdb_java.so_linux_amd64`) exists in file system next to the
   driver JAR (in the same directory). If the library file is found
   there - then the driver will attempt to load it as the last resort.

Testing: new test added that covers loading from the same dir and
loading by name.

Fixes: duckdb#444
@staticlibs staticlibs merged commit a7ce5de into duckdb:v1.4-andium Nov 10, 2025
@staticlibs staticlibs deleted the load_by_name_14 branch November 10, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant