Coder Social home page Coder Social logo

jmc734 / native-utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adamheinrich/native-utils

0.0 2.0 0.0 123 KB

A simple library class which helps with loading dynamic JNI libraries stored in the JAR archive.

License: MIT License

Java 100.00%

native-utils's Introduction

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

The class was written in 2012 by Adam Heinrich. More information can be found in accompanying blog post (http://adamheinrich.com/blog/2012/how-to-load-native-jni-library-from-jar/).

native-utils's People

Contributors

adamheinrich avatar simonlarsen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.