Package org.sosy_lab.common
Class NativeLibraries
- java.lang.Object
-
- org.sosy_lab.common.NativeLibraries
-
public final class NativeLibraries extends Object
Helper class for loading native libraries. The methods in this class search for the library binary in some more directories than those specified in the java.library.path system property.The searched directories are:
- the same directory as the JAR file of this library
- the "native library path" as returned by
getNativeLibraryPath()
, which is the directory ../native/<arch>-<os>/ relative to the JAR file of this library, with <arch>-<os> being one of the following values depending on your system:- x86_64-linux
- x86-linux
- x86-windows
- x86_64-windows
- x86-macosx
- x86_64-macosx
Standard usage is by calling the method
loadLibrary(java.lang.String)
with the library name, or useClasses.makeExtendedURLClassLoader()
andClasses.ClassLoaderBuilder.setCustomLookupNativeLibraries(java.util.function.Predicate)
if third-party code loads the library.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NativeLibraries.Architecture
Deprecated.static class
NativeLibraries.OS
Deprecated.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Optional<Path>
findPathForLibrary(String libraryName)
Deprecated.static Path
getNativeLibraryPath()
Return the "native library path" as defined in the documentation ofNativeLibraries
, i.e., a directory where members of this class expect native binaries.static void
loadLibrary(String name)
Load a native library.
-
-
-
Method Detail
-
getNativeLibraryPath
public static Path getNativeLibraryPath()
Return the "native library path" as defined in the documentation ofNativeLibraries
, i.e., a directory where members of this class expect native binaries.It is usually recommended to use the high-level method
loadLibrary(String)
instead.
-
loadLibrary
public static void loadLibrary(String name)
Load a native library. This is similar toSystem.loadLibrary(String)
, but first searches for the library in some other directories (as explained inNativeLibraries
). If the library cannot be found there, it falls back toSystem.loadLibrary(String)
, which looks in the directories specified in the java.library.path system property.If you cannot replace the call to
System.loadLibrary(String)
, you can use a class loader created withClasses.makeExtendedURLClassLoader()
andClasses.ClassLoaderBuilder.setCustomLookupNativeLibraries(java.util.function.Predicate)
to letSystem.loadLibrary(String)
use the same lookup mechanism as this method.- Parameters:
name
- A library name as forSystem.loadLibrary(String)
.
-
findPathForLibrary
@Deprecated public static Optional<Path> findPathForLibrary(String libraryName)
Deprecated.Search for a native library in some directories as listed in the documentation ofNativeLibraries
.- Parameters:
libraryName
- A library name as forSystem.loadLibrary(String)
.- Returns:
- Found path or
Optional.absent()
-
-