This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new ed81e598 GH-882: Add support for loading native library from a user 
specified location (#883)
ed81e598 is described below

commit ed81e5981a2bee40584b3a411ed755cb4cc5b91f
Author: Pepijn Van Eeckhoudt <[email protected]>
AuthorDate: Tue Oct 28 00:57:13 2025 +0100

    GH-882: Add support for loading native library from a user specified 
location (#883)
    
    ## What's Changed
    
    Add an opt-in code path that attempts to load the native library
    relative to the path specified by the `arrow.cdata.library.path` system
    property.
    
    Closes #882.
---
 c/src/main/java/org/apache/arrow/c/jni/JniLoader.java | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java 
b/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java
index f712b400..46c93f55 100644
--- a/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java
+++ b/c/src/main/java/org/apache/arrow/c/jni/JniLoader.java
@@ -75,8 +75,23 @@ public class JniLoader {
   }
 
   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
+      }
+    }
+
+    final String libraryToLoad = name + "/" + getNormalizedArch() + "/" + 
libraryName;
     try {
       File temp =
           File.createTempFile("jnilib-", ".tmp", new 
File(System.getProperty("java.io.tmpdir")));

Reply via email to