From 47befcbde8ce3ce114b590764a86caa6c2b4e654 Mon Sep 17 00:00:00 2001 From: Mark Kittisopikul Date: Thu, 7 Jul 2022 17:21:44 -0400 Subject: [PATCH] Set jna.library.path->java.library.path if not set The heart of the issue is that currently, the native launcher only sets java.library.path and does not set jna.library.path. JNA will only look in jna.library.path for versioned shared libraries such as libblosc.so.1. Within java.library.path, JBlosc will only look for libblosc.so. On macOS or Linux, JBlosc will happily find libblosc.so.1 within system folders since they are on the jna.library.path by default. Within ImageJ2, JBlosc will not look in the lib folder for libblosc.so.1 because it is not on the jna.library.path. This pull request will enable JNA apps within ImageJ2 to act like JNA apps outside of ImageJ2. They will both be able to locate libblosc.so.1 whether it is installed within ImageJ2 or by the system. Otherwise to include binaries in ImageJ2, we would have to compile a special version for ImageJ2 that links to libblosc.so. That binary will not work on Ubuntu Linux which only bundles libblosc.so.1. In the primary libblosc package. libblosc.so is only included in libblosc-dev. A specific application of the issue is coordination between JBlosc and the HDF5 Blosc plugin. Binaries within ImageJ2 should be able to work outside of ImageJ2. For this to happen they should link to versioned libraries like libblosc.so.1 rather than unversioned dev libraries like libblosc.so. This PR allows JNA and native libraries to link against the same versioned library (e.g. libblosc.so.1). Closes scijava/scijava-common#438. Co-authored-by: Curtis Rueden --- src/main/java/net/imagej/launcher/ClassLauncher.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/net/imagej/launcher/ClassLauncher.java b/src/main/java/net/imagej/launcher/ClassLauncher.java index 4940547..446ec36 100644 --- a/src/main/java/net/imagej/launcher/ClassLauncher.java +++ b/src/main/java/net/imagej/launcher/ClassLauncher.java @@ -59,6 +59,13 @@ public class ClassLauncher { } catch (Throwable t) { // ignore; Java 1.4 pretended that getenv() goes away } + + // Allow Java Native Access (JNA) to search java.library.path + // for versioned shared libraries on Linux. + final String java_library_path = System.getProperty("java.library.path"); + if (java_library_path != null && System.getProperty("jna.library.path") == null) { + System.setProperty("jna.library.path", java_library_path); + } } protected static String[] originalArguments;