Load DuckDB native library by name first #421
Open
+50
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When loading a native library, attempt to first load the library,
duckdb_java
, by name. Only when that fails, loading will revert to the old behaviour of searching via classpath/local file path.The main motivation for this work was to allow creating a correct Native Image that will not have issues during initialization. The change does not provide the support out-of-the-box.
But it works in Native Image if someone (like us) extracts the native library (wrt OS/Arch), renames it to follow the specification and places it on JNI search path.
For
System.loadLibrary
to work, the native library has to have the correct prefix (lib
for Mac/Linux, nolib
for Windows) and suffix (.so
,.dll
or.dylib
for Linux/Windows/Mac, respectively). No architecture suffix is allowed.As it stands the current packaging logic does not create native library files with the right names but that seems like a deeper change in the build setup. Also, I have zero knowledge about how the artifacts are being used internally, in dev work, so I don't feel comfortable with changing it without guidance.
One could look at sqlite-jdbc for some inspiration on how to improve it (which is roughly what we had to do when repackaging DuckDB's Java client jar).
Also, if maintainers are fine with this change we can also include Native Image configuration in the final
duckdb_jdbc.jar
which is a requirement for GraalVM's Native Image. More and more Java libraries provide similar Native Image configuration.That would mostly enable #180.