Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions c/src/main/java/org/apache/arrow/c/jni/JniLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,23 @@ private synchronized void loadRemaining() {
}

private void load(String name) {
final String libraryToLoad =
name + "/" + getNormalizedArch() + "/" + System.mapLibraryName(name);
String libraryName = System.mapLibraryName(name);

// If 'arrow.cdata.library.path' is defined, try to load the native library from there
String libraryPath = System.getProperty("arrow.cdata.library.path");
if (libraryPath != null) {
try {
File libraryFile = new File(libraryPath, libraryName);
if (libraryFile.isFile()) {
System.load(libraryFile.getAbsolutePath());
return;
}
} catch (UnsatisfiedLinkError e) {
// Ignore this error and fall back to extracting from the JAR file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, would it be better to error if the property is provided but the file doesn't exist? That way you don't unexpectedly/silently fall back when you intended to load from somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my specific application the native library will be have been stripped from the jar and loading will fail so the end result will be the same either way.

I modeled this on examples like the ones I referenced where possible alternatives are tried in a specified order. Happy to change this to fail early though. Let me know what you would prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we can leave it as is then.

}
}

final String libraryToLoad = name + "/" + getNormalizedArch() + "/" + libraryName;
try {
File temp =
File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir")));
Expand Down
Loading