Class RulesJni

java.lang.Object
com.github.fmeum.rules_jni.RulesJni

public final class RulesJni extends Object
Static helper methods that load native libraries created with the cc_jni_library rule of rules_jni.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Path
    extractLibrary(String name, Class<?> inSamePackageAs)
    Extracts a native library created with the cc_jni_library rule from the resource directory of the class inSamePackageAs to a temporary file.
    static Path
    extractLibrary(String name, String absolutePathToPackage)
    Loads a native library created with the cc_jni_library rule from the resource directory specified by the absolute path absolutePathToPackage.
    static void
    loadLibrary(String name, Class<?> inSamePackageAs)
    Loads a native library created with the cc_jni_library rule from the resource directory of the class inSamePackageAs.
    static void
    loadLibrary(String name, String absolutePathToPackage)
    Loads a native library created with the cc_jni_library rule from the resource directory specified by the absolute path absolutePathToPackage.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • loadLibrary

      public static void loadLibrary(String name, Class<?> inSamePackageAs)
      Loads a native library created with the cc_jni_library rule from the resource directory of the class inSamePackageAs.

      The correct version of the native library for the current OS and CPU architecture is chosen automatically.

      All temporary files created during the extraction of the native library are cleaned up at JVM exit.

      Parameters:
      name - the name of the cc_jni_library target that generates the native library to be loaded.
      inSamePackageAs - a class that is contained in the same Java (or Bazel) package as the native library.
      Throws:
      NullPointerException - if name or inSamePackageAs is null.
      SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library.
      UnsatisfiedLinkError - if a version of the library for the current OS and CPU architecture could not be found in the resource directory corresponding to inSamePackageAs or extracting the library failed.
    • loadLibrary

      public static void loadLibrary(String name, String absolutePathToPackage)
      Loads a native library created with the cc_jni_library rule from the resource directory specified by the absolute path absolutePathToPackage.

      The correct version of the native library for the current OS and CPU architecture is chosen automatically.

      All temporary files created during the extraction of the native library are cleaned up at JVM exit.

      Parameters:
      name - the name of the cc_jni_library target that generates the native library to be loaded.
      absolutePathToPackage - a class that is contained in the same Java (or Bazel) package as the native library.
      Throws:
      NullPointerException - if name or absolutePathToPackage is null.
      SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library.
      UnsatisfiedLinkError - if a version of the library for the current OS and CPU architecture could not be found in the specified resource directory or extracting the library failed.
    • extractLibrary

      public static Path extractLibrary(String name, Class<?> inSamePackageAs) throws IOException
      Extracts a native library created with the cc_jni_library rule from the resource directory of the class inSamePackageAs to a temporary file.

      The correct version of the native library for the current OS and CPU architecture is chosen automatically.

      All temporary files created during the extraction of the native library are cleaned up at JVM exit.

      Parameters:
      name - the name of the cc_jni_library target that generates the native library to be loaded.
      inSamePackageAs - a class that is contained in the same Java (or Bazel) package as the native library.
      Throws:
      NullPointerException - if name or inSamePackageAs is null.
      SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library.
      UnsatisfiedLinkError - if a version of the library for the current OS and CPU architecture could not be found in the resource directory corresponding to inSamePackageAs.
      IOException - if extracting the library failed.
    • extractLibrary

      public static Path extractLibrary(String name, String absolutePathToPackage) throws IOException
      Loads a native library created with the cc_jni_library rule from the resource directory specified by the absolute path absolutePathToPackage.

      The correct version of the native library for the current OS and CPU architecture is chosen automatically.

      All temporary files created during the extraction of the native library are cleaned up at JVM exit.

      Parameters:
      name - the name of the cc_jni_library target that generates the native library to be loaded.
      absolutePathToPackage - a class that is contained in the same Java (or Bazel) package as the native library.
      Throws:
      NullPointerException - if name or absolutePathToPackage is null.
      SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library.
      UnsatisfiedLinkError - if a version of the library for the current OS and CPU architecture could not be found in the specified resource directory or extracting the library failed.
      IOException - if extracting the library failed.