Skip to content

Commit 27958cd

Browse files
committed
#882 Add support for loading native library from a user specified location
1 parent aee8a10 commit 27958cd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

c/src/main/java/org/apache/arrow/c/jni/JniLoader.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,23 @@ private synchronized void loadRemaining() {
7575
}
7676

7777
private void load(String name) {
78-
final String libraryToLoad =
79-
name + "/" + getNormalizedArch() + "/" + System.mapLibraryName(name);
78+
String libraryName = System.mapLibraryName(name);
79+
80+
// If 'arrow.cdata.library.path' is defined, try to load the native library from there
81+
String libraryPath = System.getProperty("arrow.cdata.library.path");
82+
if (libraryPath != null) {
83+
try {
84+
File libraryFile = new File(libraryPath, libraryName);
85+
if (libraryFile.isFile()) {
86+
System.load(libraryFile.getAbsolutePath());
87+
return;
88+
}
89+
} catch (UnsatisfiedLinkError e) {
90+
// Ignore this error and fall back to extracting from the JAR file
91+
}
92+
}
93+
94+
final String libraryToLoad = name + "/" + getNormalizedArch() + "/" + libraryName;
8095
try {
8196
File temp =
8297
File.createTempFile("jnilib-", ".tmp", new File(System.getProperty("java.io.tmpdir")));

0 commit comments

Comments
 (0)