Top Description Fields Constructors Methods
org.lwjgl.system

public final Class Library

extends Object
Class Inheritance
Imports
org.lwjgl.*, javax.annotation.*, java.io.*, java.lang.reflect.*, java.net.*, java.nio.channels.*, java.nio.file.*, java.security.*, java.util.*, java.util.function.*, java.util.jar.*, java.util.regex.*

Initializes the LWJGL shared library and handles loading additional shared libraries.
See Also
Configuration#LIBRARY_NAME, Configuration#LIBRARY_PATH

Field Summary

Modifier and TypeField and Description
pack-priv static final String
public static final String
JNI_LIBRARY_NAME

The LWJGL shared library name.

private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
checkHash(Class<?>
the class to use to discover the shared library hash in the classpath
context
,
Path
the library file loaded
libFile
,
String module, String libName)

Compares the shared library hash stored in the classpath, with the hash of the actual library loaded at runtime.

private static void
detectPlatformMismatch(Class<?> context, String module)

pack-priv static Path
findFile(String path, String module, String file, boolean bundledWithLWJGL)

private static Path
findFile(String path, String file)

pack-priv static URL
findResource(Class<?> context, String module, String resource, boolean bundledWithLWJGL)

private static String
getBundledPath(String module, String resource)

pack-priv static String
private static byte[]
getSHA1(URL hashURL)

private static byte[]
getSHA1(Path libFile)

public static void
initialize()

Ensures that the LWJGL shared library has been loaded.

public static SharedLibrary
loadNative(String module, String name)

Calls loadNative(Class, String, String) using Library.class as the context parameter.

public static SharedLibrary

Returns:

the shared library
loadNative
(Class<?>
the class to use to discover the shared library in the classpath
context
,
String
the module to which the shared library belongs
module
,
String
the library name. OS-specific prefixes and file extensions are optional (e.g. both "GL" and "libGL.so.1" are valid on Linux)
name
)

Loads a shared library using OS-specific APIs (e.g. LoadLibrary or dlopen).

public static SharedLibrary

Returns:

the shared library
loadNative
(Class<?>
the class to use to discover the shared library in the classpath
context
,
String
the module to which the shared library belongs
module
,
String
the library name. OS-specific prefixes and file extensions are optional (e.g. both "GL" and "libGL.so.1" are valid on Linux)
name
,
boolean
whether the default LWJGL distribution includes the shared library. If true, LWJGL will also try to find the shared library under the <platform>/<arch>/<module> subfolder.
bundledWithLWJGL
)

Loads a shared library using OS-specific APIs (e.g. LoadLibrary or dlopen).

private static SharedLibrary
loadNative(Class<?> context, String module, String name, boolean bundledWithLWJGL, boolean printError)

private static SharedLibrary
loadNative(Class<?> context, String module, String libName, boolean bundledWithLWJGL, String property, String paths)

public static SharedLibrary

Returns:

the shared library
loadNative
(Class<?> context, String module, Configuration<String>
a Configuration that specifies the library name
name
,
String...
the default library name(s)
defaultNames
)

Loads a shared library using loadNative(String, String) with the name specified by name.

public static SharedLibrary

Returns:

the shared library
loadNative
(Class<?> context, String module, Configuration<String>
a Configuration that specifies the library name
name
,
Supplier<SharedLibrary>
fallback to use if everything else fails
fallback
,
String...
the default library name(s)
defaultNames
)

Loads a shared library using loadNative(String, String) with the name specified by name.

private static SharedLibrary
loadNativeFromLibraryPath(Class<?> context, String module, String libName, boolean bundledWithLWJGL)

private static SharedLibrary
public static void
loadSystem(String module, String name)

Calls loadSystem(Consumer, Consumer, Class, String, String) using Library.class as the context parameter.

public static void
loadSystem(Consumer<String>
should be the System::load expression. This ensures that System.load has the same caller as this method.
load
,
Consumer<String>
should be the System::loadLibrary expression. This ensures that System.loadLibrary has the same caller as this method.
loadLibrary
,
Class<?>
the class to use to discover the shared library in the classpath
context
,
String
the module to which the shared library belongs
module
,
String
the library name. If not an absolute path, it must be the plain library name, without an OS specific prefix or file extension (e.g. GL, not libGL.so)
name
)

Loads a JNI shared library.

private static boolean
loadSystem(Consumer<String> load, Class<?> context, String module, String libName, boolean bundledWithLWJGL, String property, String paths)

private static boolean
loadSystemFromLibraryPath(Consumer<String> load, Class<?> context, String module, String libName, boolean bundledWithLWJGL)

private static void
printError(boolean bundledWithLWJGL)

pack-priv static void
printError(String message)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

JAVA_LIBRARY_PATHback to summary
pack-priv static final String JAVA_LIBRARY_PATH
JNI_LIBRARY_NAMEback to summary
public static final String JNI_LIBRARY_NAME

The LWJGL shared library name.

NATIVES_JARback to summary
private static final Pattern NATIVES_JAR
PATH_SEPARATORback to summary
private static final Pattern PATH_SEPARATOR

Constructor Detail

Libraryback to summary
private Library()

Method Detail

checkHashback to summary
private static void checkHash(Class<?> context, Path libFile, String module, String libName)

Compares the shared library hash stored in the classpath, with the hash of the actual library loaded at runtime.

This check prints a simple warning when there's a hash mismatch, to help diagnose installation/classpath issues. It is not a security feature.

Parameters
context:Class<?>

the class to use to discover the shared library hash in the classpath

libFile:Path

the library file loaded

detectPlatformMismatchback to summary
private static void detectPlatformMismatch(Class<?> context, String module)
findFileback to summary
pack-priv static Path findFile(String path, String module, String file, boolean bundledWithLWJGL)
Annotations
@Nullable
findFileback to summary
private static Path findFile(String path, String file)
Annotations
@Nullable
findResourceback to summary
pack-priv static URL findResource(Class<?> context, String module, String resource, boolean bundledWithLWJGL)
Annotations
@Nullable
getBundledPathback to summary
private static String getBundledPath(String module, String resource)
getRegularFilePathback to summary
pack-priv static String getRegularFilePath(URL url)
Annotations
@Nullable
getSHA1back to summary
private static byte[] getSHA1(URL hashURL) throws IOException
getSHA1back to summary
private static byte[] getSHA1(Path libFile) throws NoSuchAlgorithmException, IOException
initializeback to summary
public static void initialize()

Ensures that the LWJGL shared library has been loaded.

loadNativeback to summary
public static SharedLibrary loadNative(String module, String name)

Calls loadNative(Class, String, String) using Library.class as the context parameter.

loadNativeback to summary
public static SharedLibrary loadNative(Class<?> context, String module, String name)

Loads a shared library using OS-specific APIs (e.g. LoadLibrary or dlopen).

Parameters
context:Class<?>

the class to use to discover the shared library in the classpath

module:String

the module to which the shared library belongs

name:String

the library name. OS-specific prefixes and file extensions are optional (e.g. both "GL" and "libGL.so.1" are valid on Linux)

Returns:SharedLibrary

the shared library

Annotations
@SuppressWarnings:try
Exceptions
UnsatisfiedLinkError:
if the library could not be loaded
loadNativeback to summary
public static SharedLibrary loadNative(Class<?> context, String module, String name, boolean bundledWithLWJGL)

Loads a shared library using OS-specific APIs (e.g. LoadLibrary or dlopen).

Parameters
context:Class<?>

the class to use to discover the shared library in the classpath

module:String

the module to which the shared library belongs

name:String

the library name. OS-specific prefixes and file extensions are optional (e.g. both "GL" and "libGL.so.1" are valid on Linux)

bundledWithLWJGL:boolean

whether the default LWJGL distribution includes the shared library. If true, LWJGL will also try to find the shared library under the <platform>/<arch>/<module> subfolder.

Returns:SharedLibrary

the shared library

Exceptions
UnsatisfiedLinkError:
if the library could not be loaded
loadNativeback to summary
private static SharedLibrary loadNative(Class<?> context, String module, String name, boolean bundledWithLWJGL, boolean printError)
Annotations
@SuppressWarnings:try
loadNativeback to summary
private static SharedLibrary loadNative(Class<?> context, String module, String libName, boolean bundledWithLWJGL, String property, String paths)
Annotations
@Nullable
loadNativeback to summary
public static SharedLibrary loadNative(Class<?> context, String module, Configuration<String> name, String... defaultNames)

Loads a shared library using loadNative(String, String) with the name specified by name. If name is not set, loadNative(String, String) will be called with the names specified by defaultNames. The first successful will be returned.

Parameters
name:Configuration<String>

a Configuration that specifies the library name

defaultNames:String[]

the default library name(s)

Returns:SharedLibrary

the shared library

Exceptions
UnsatisfiedLinkError:
if the library could not be loaded
loadNativeback to summary
public static SharedLibrary loadNative(Class<?> context, String module, Configuration<String> name, Supplier<SharedLibrary> fallback, String... defaultNames)

Loads a shared library using loadNative(String, String) with the name specified by name. If name is not set, loadNative(String, String) will be called with the names specified by defaultNames. The first successful will be returned. If the library could not be loaded, the fallback will be called.

Parameters
name:Configuration<String>

a Configuration that specifies the library name

fallback:Supplier<SharedLibrary>

fallback to use if everything else fails

defaultNames:String[]

the default library name(s)

Returns:SharedLibrary

the shared library

Exceptions
UnsatisfiedLinkError:
if the library could not be loaded
loadNativeFromLibraryPathback to summary
private static SharedLibrary loadNativeFromLibraryPath(Class<?> context, String module, String libName, boolean bundledWithLWJGL)
Annotations
@Nullable
loadNativeFromSystemback to summary
private static SharedLibrary loadNativeFromSystem(String libName)
Annotations
@Nullable
loadSystemback to summary
public static void loadSystem(String module, String name) throws UnsatisfiedLinkError

Calls loadSystem(Consumer, Consumer, Class, String, String) using Library.class as the context parameter.

loadSystemback to summary
public static void loadSystem(Consumer<String> load, Consumer<String> loadLibrary, Class<?> context, String module, String name) throws UnsatisfiedLinkError

Loads a JNI shared library.

Parameters
load:Consumer<String>

should be the System::load expression. This ensures that System.load has the same caller as this method.

loadLibrary:Consumer<String>

should be the System::loadLibrary expression. This ensures that System.loadLibrary has the same caller as this method.

context:Class<?>

the class to use to discover the shared library in the classpath

module:String

the module to which the shared library belongs

name:String

the library name. If not an absolute path, it must be the plain library name, without an OS specific prefix or file extension (e.g. GL, not libGL.so)

Annotations
@SuppressWarnings:try
Exceptions
UnsatisfiedLinkError:
if the library could not be loaded
loadSystemback to summary
private static boolean loadSystem(Consumer<String> load, Class<?> context, String module, String libName, boolean bundledWithLWJGL, String property, String paths)
loadSystemFromLibraryPathback to summary
private static boolean loadSystemFromLibraryPath(Consumer<String> load, Class<?> context, String module, String libName, boolean bundledWithLWJGL)
printErrorback to summary
private static void printError(boolean bundledWithLWJGL)
printErrorback to summary
pack-priv static void printError(String message)