bmarwell / libloader

A configurable and extendable loader for native libraries to use with JNI.
Apache License 2.0
2 stars 0 forks source link

[[native-libloader]] = native-libloader

A configurable and extendable loader for native libraries to use with JNI.

== Description

When using the https://docs.oracle.com/javase/8/docs/technotes/guides/jni/index.html[Java Native Interface], one faces the problem to ship the corresponding libraries (.dll for Windows, .dylib for Mac and .so for others) with their app.

Imagine you could use a mechanism to load those from .jar files you included in your application.

The Native LibLoader aims to provide such a mechanism. It was inspired by the https://github.com/scijava/native-lib-loader[scijava/native-lib-loader] and the https://github.com/trustin/os-maven-plugin[trustin/os-maven-plugin].

== Requirements

This library only requires Java 6 and has no runtime dependencies.

== Usage

[source,java]

import io.github.java_native.libloader.LibLoader; import io.github.java_native.libloader.LibLoaderResult; import io.github.java_native.libloader.NativeLibLoader;

public class Demo { public static void main(String[] args) { NativeLibLoader libLoader = LibLoader.getLibLoader();

    /* will load 'natives/linux-x86_64-64/libjssc.so' on linux. */
    final LibLoaderResult loadLibrary = libLoader.loadLibrary("jssc");

    /* LibLoaderResult has no fields at the moment. */
}

}

The LibLoader is fully configurable, read below for more information.

== Enhancements

This library loader has the following advancements over the existing lib loaders:

== Naming convention

The path names inside the .jar files are aligned to the https://github.com/trustin/os-maven-plugin/[os-maven-plugin]. It follows the same conventions as the https://github.com/google/osdetector-gradle-plugin[osdetector-gradle-plugin].

osname-arch-bitness[-qualifier]

== Supported systems

Currently, the following systems are built in: