Interface JarJniLoader


  • public interface JarJniLoader
    Loads native libraries from JAR files.
    • Method Summary

      Static Methods 
      Modifier and Type Method Description
      static <T> void loadLib​(Class<T> cls, String jarPathPrefix, String name)
      Loads a native library from a JAR file.
      static <T> void loadLib​(Class<T> cls, String jarPathPrefix, String name, String platformDir)
      Loads a native library from a JAR file.
    • Method Detail

      • loadLib

        static <T> void loadLib​(Class<T> cls,
                                String jarPathPrefix,
                                String name,
                                String platformDir)
        Loads a native library from a JAR file.
        Parameters:
        cls - The class to use for loading the library.
        jarPathPrefix - The path prefix to the library in the JAR file.
        name - The name of the library, sans "lib" prefix and ".so|.dll|.dylib" suffix.
        platformDir - The platform-specific subdirectory (inside jarPathPrefix) to load the library from, or null to search for the dynamic library directly within jarPathPrefix.
      • loadLib

        static <T> void loadLib​(Class<T> cls,
                                String jarPathPrefix,
                                String name)
        Loads a native library from a JAR file.

        The library is loaded from the platform-specific subdirectory of the jarPathPrefix.

        The platform-specific subdirectory derived from the current platform and the architecture of the JVM as determined by OsInfo.PLATFORM.

        For example if executing, JarJniLoader.loadLib(MyClass.class, "/native", "mylib"); on a 64-bit x86 Linux system, the library will be loaded from "/native/linux-amd64/libmylib.so" from the same JAR file that contains MyClass.class. If executing on an Apple Silicon Macbook, the library will be loaded from "/native/mac_os_x-arm64/libmylib.dylib". From Windows 11, the library will be loaded from "/native/windows-amd64/mylib.dll" (note, no "lib" prefix).

        Parameters:
        cls - The class to use for loading the library.
        jarPathPrefix - The path prefix to the library in the JAR file.
        name - The name of the library, sans "lib" prefix and ".so|.dll|.dylib" suffix.