1
0
Fork
You've already forked native-utils
0
A simple library class which helps with loading dynamic JNI libraries stored in the JAR archive https://github.com/adamheinrich/native-utils
  • Java 100%
Find a file
Adam Heinrich e6a3948966 Fix testLoadLibraryNullPath() test case ( #12 )
The tested method throws IllegalArgumentException instead of
NullPointerException when called with a null argument.
2018年07月19日 21:28:16 +02:00
src Fix testLoadLibraryNullPath() test case ( #12 ) 2018年07月19日 21:28:16 +02:00
.gitignore Moved to maven project structure 2016年04月18日 07:53:29 +01:00
LICENSE Initial commit 2015年06月14日 10:04:53 +02:00
pom.xml Add basic unit tests 2017年10月24日 22:13:38 +02:00
README.md Update README.md 2016年04月20日 13:22:14 +02:00

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

  • The temporary file is stored into temp directory specified by java.io.tmpdir (by default it’s the operating system’s temporary directory). It should be automatically deleted when the application exits.
  • Although the code has some try-finally section (to be sure that streams are closed properly in case an exception is thrown), it does not catch exceptions. The exception has to be handled by the application. I belive this approach is cleaner and has some benefits.

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.