From 4727fc60f17a67b40c2bdf200a518a5d5708804c Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Thu, 7 Apr 2016 19:06:53 +0200 Subject: [PATCH] Try to load lz4-java from java.library.path, then fallback to bundled Use system-provided lz4-java, if it's available on the java.library.path (the default location where Java looks for native libraries), and fallback to bundled binary if it's not. This allows user to use lz4 java even on systems that are not directly supported, like Linux with musl libc, uClibc etc. --- src/java/net/jpountz/util/Native.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/java/net/jpountz/util/Native.java b/src/java/net/jpountz/util/Native.java index 1856841..e25708e 100644 --- a/src/java/net/jpountz/util/Native.java +++ b/src/java/net/jpountz/util/Native.java @@ -71,6 +71,16 @@ public static synchronized void load() { if (loaded) { return; } + + // Try to load lz4-java (liblz4-java.so on Linux) from the java.library.path. + try { + System.loadLibrary("lz4-java"); + loaded = true; + return; + } catch (UnsatisfiedLinkError ex) { + // Doesn't exist, so proceed to loading bundled library. + } + String resourceName = resourceName(); InputStream is = Native.class.getResourceAsStream(resourceName); if (is == null) {