Class LibUtils

java.lang.Object
org.jocl.LibUtils

public final class LibUtils extends Object
Utility class for detecting the operating system and architecture types, and automatically loading the matching native library as a resource or from a file.

This class is not intended to be used by clients.

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Create the full library file name, including the extension and prefix, for the given library name.
    static String
    Creates the name for the native library with the given base name for the current platform, by appending strings that indicate the current operating system and architecture.

    The resulting name will be of the form
    baseName-OSType-ArchType
    where OSType and ArchType are the lower case Strings of the respective OSType and ArcType enum constants.

    For example, the library name with the base name "EXAMPLE" may be
    EXAMPLE-windows-x86

    Note that the resulting name will not include any platform specific prefixes or extensions for the actual name.
    static void
    loadLibrary(String libraryName, String... dependentLibraryNames)
    Loads the specified library.

    Methods inherited from class Object

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

    • loadLibrary

      public static void loadLibrary(String libraryName, String... dependentLibraryNames)
      Loads the specified library.

      The method will attempt to load the library using the usual System.loadLibrary call. In this case, the specified dependent libraries are ignored, because they are assumed to be loaded automatically in the same way as the main library.

      If the library can not be loaded with the System.loadLibrary call, then this method will attempt to load the file as a resource (usually one that is contained in a JAR file). In this case, the library is assumed to be located in subdirectory called "/lib" inside the JAR file. The method will try to load a resource that has the platform-specific library file name from this directory, extract it into the default directory for temporary files, and load the library from there.

      In this case, the specified dependent libraries may also be loaded as resources. They are assumed to be located in subdirectories that are named according to the osString() and archString() of the executing platform. For example, such a library may be located in a directory inside the JAR that is called "/lib/windows/x86_64". These dependent libraries will be extracted and loaded before the main library is loaded.
      Parameters:
      libraryName - The name of the library (without a platform specific prefix or file extension)
      dependentLibraryNames - The names of libraries that the library to load depends on. If the library is loaded as a resource, then it will be attempted to also load these libraries as resources, as described above
      Throws:
      UnsatisfiedLinkError - if the native library could not be loaded.
    • createLibraryFileName

      public static String createLibraryFileName(String libraryName)
      Create the full library file name, including the extension and prefix, for the given library name. For example, the name "EXAMPLE" will become
      EXAMPLE.dll on Windows
      libEXAMPLE.so on Linux
      EXAMPLE.dylib on MacOS
      Parameters:
      libraryName - The library name
      Returns:
      The full library name, with extension
    • createPlatformLibraryName

      public static String createPlatformLibraryName(String baseName)
      Creates the name for the native library with the given base name for the current platform, by appending strings that indicate the current operating system and architecture.

      The resulting name will be of the form
      baseName-OSType-ArchType
      where OSType and ArchType are the lower case Strings of the respective OSType and ArcType enum constants.

      For example, the library name with the base name "EXAMPLE" may be
      EXAMPLE-windows-x86

      Note that the resulting name will not include any platform specific prefixes or extensions for the actual name.
      Parameters:
      baseName - The base name of the library
      Returns:
      The library name