adamheinrich / native-utils

A simple library class which helps with loading dynamic JNI libraries stored in the JAR archive
https://www.adamheinrich.com/blog/2012/12/how-to-load-native-jni-library-from-jar/
MIT License
248 stars 90 forks source link

Native Utils

A simple library class which helps with loading dynamic libraries stored in the JAR archive. These libraries usualy contain implementation of some methods in native code (using JNI - Java Native Interface).

Notes

Usage

To load the dynamic library, just make sure it is packed inside the JAR archive and call method loadLibraryFromJar:

import cz.adamh.NativeUtils;

public class HelloJNI {  
    static {   
        try {    
            NativeUtils.loadLibraryFromJar("/resources/libHelloJNI.so");   
        } catch (IOException e) {
            // This is probably not the best way to handle exception :-)    
            e.printStackTrace();
        }    
    }  

    public native void hello();    
}

More information

More information can be found in accompanying blog post.