Skip to content

Commit

Permalink
Set jna.library.path->java.library.path if not set
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mkitti and ctrueden committed Sep 14, 2022
1 parent f5942cb commit 47befcb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/net/imagej/launcher/ClassLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

2 comments on commit 47befcb

@imagesc-bot
Copy link

Choose a reason for hiding this comment

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

This commit has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/imagej-tensorflow-now-with-command-to-change-tensorflow-library-version-switch-to-gpu/31744/15

@imagesc-bot
Copy link

Choose a reason for hiding this comment

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

This commit has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-august-2020-update-broke-mobie/41236/31

Please sign in to comment.