diff --git a/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java b/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java index 7960bbbb..da25e825 100755 --- a/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java +++ b/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java @@ -86,6 +86,8 @@ public class Library { final private String version; final private ClassLoader classLoader; private boolean loaded; + private String nativeLibraryPath; + private URL nativeLibrarySourceUrl; public Library(String name) { this(name, null, null); @@ -116,6 +118,24 @@ private static String version(Class clazz) { return null; } + /** + * Get the path to the native library loaded. + * @return the path (should not be null once the library is loaded) + * @since 1.16 + */ + public String getNativeLibraryPath() { + return nativeLibraryPath; + } + + /** + * Get the URL to the native library source that has been extracted (if it was extracted). + * @return the url to the source (in classpath) + * @since 1.16 + */ + public URL getNativeLibrarySourceUrl() { + return nativeLibrarySourceUrl; + } + public static String getOperatingSystem() { String name = System.getProperty("os.name").toLowerCase().trim(); if( name.startsWith("linux") ) { @@ -147,7 +167,7 @@ public static int getBitModel() { } /** - * + * Load the native library. */ synchronized public void load() { if( loaded ) { @@ -181,11 +201,11 @@ private void doLoad() { } /* Try loading library from java library path */ - if( version!=null && load(errors, name + getBitModel() + "-" + version) ) + if( version!=null && loadLibrary(errors, name + getBitModel() + "-" + version) ) return; - if( version!=null && load(errors, name + "-" + version) ) + if( version!=null && loadLibrary(errors, name + "-" + version) ) return; - if( load(errors, name ) ) + if( loadLibrary(errors, name) ) return; @@ -262,6 +282,7 @@ final public String getLibraryFileName() { *
  • no directory
  • * * @return the list + * @since 1.15 */ final public String[] getSpecificSearchDirs() { return new String[] { @@ -292,6 +313,7 @@ private boolean extractAndLoad(ArrayList errors, String customPath, S File target = extract(errors, resource, prefix, suffix, path); if( target!=null ) { if( load(errors, target) ) { + nativeLibrarySourceUrl = resource; return true; } } @@ -409,6 +431,7 @@ private void chmod755(File file) { private boolean load(ArrayList errors, File lib) { try { System.load(lib.getPath()); + nativeLibraryPath = lib.getPath(); return true; } catch (UnsatisfiedLinkError e) { LinkageError le = new LinkageError("Unable to load library from " + lib); @@ -418,9 +441,10 @@ private boolean load(ArrayList errors, File lib) { return false; } - private boolean load(ArrayList errors, String lib) { + private boolean loadLibrary(ArrayList errors, String lib) { try { System.loadLibrary(lib); + nativeLibraryPath = "java.library.path,sun.boot.library.pathlib:" + lib; return true; } catch (UnsatisfiedLinkError e) { LinkageError le = new LinkageError("Unable to load library " + lib);