Package com.sun.jna
Klasse NativeLibrary
java.lang.Object
com.sun.jna.NativeLibrary
- Alle implementierten Schnittstellen:
Closeable
,AutoCloseable
Provides management of native library resources. One instance of this
class corresponds to a single loaded native library. May also be used
to map to the current process (see
getProcess()
).
Library Search Paths A search for a given library will scan the following locations:
jna.library.path
User-customizable pathjna.platform.library.path
Platform-specific paths- On OSX,
~/Library/Frameworks
,/Library/Frameworks
, and/System/Library/Frameworks
will be searched for a framework with a name corresponding to that requested. Absolute paths to frameworks are also accepted, either ending at the framework name (sans ".framework") or the full path to the framework shared library (e.g. CoreServices.framework/CoreServices). - Context class loader classpath. Deployed native libraries may be
installed on the classpath under
${os-prefix}/LIBRARY_FILENAME
, where${os-prefix}
is the OS/Arch prefix returned byPlatform.getNativeLibraryResourcePrefix()
. If bundled in a jar file, the resource will be extracted tojna.tmpdir
for loading, and later removed (but only ifjna.nounpack
is false or not set).
jna.debug_load=true
to make
JNA print the steps of its library search to the console.- Autor:
- Wayne Meissner, split library loading from Function.java, twall
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic final void
addSearchPath
(String libraryName, String path) Add a path to search for the specified library, ahead of any system paths.void
close()
Close the native library we're mapped to.void
dispose()
Veraltet.(Package privat) static void
Close all open native libraries.getFile()
Returns the file on disk corresponding to this NativeLibrary instance.getFunction
(String functionName) Create a newFunction
that is linked with a native function that follows the NativeLibrary's calling convention.getFunction
(String functionName, int callFlags) Create a newFunction
that is linked with a native function that follows a given calling flags.getFunction
(String functionName, int callFlags, String encoding) Create a newFunction
that is linked with a native function that follows a given calling flags.(Package privat) Function
getFunction
(String name, Method method) Create a newFunction
that is linked with a native function that follows the NativeLibrary's calling convention.getGlobalVariableAddress
(String symbolName) Look up the given global variable within this library.static final NativeLibrary
getInstance
(String libraryName) Returns an instance of NativeLibrary for the specified name.static final NativeLibrary
getInstance
(String libraryName, ClassLoader classLoader) Returns an instance of NativeLibrary for the specified name.static final NativeLibrary
getInstance
(String libraryName, Map<String, ?> libraryOptions) Returns an instance of NativeLibrary for the specified name.getName()
Returns the simple name of this library.static final NativeLibrary
Returns an instance of NativeLibrary which refers to the current process.static final NativeLibrary
getProcess
(Map<String, ?> options) Returns an instance of NativeLibrary which refers to the current process.(Package privat) long
getSymbolAddress
(String name) Used by the Function class to locate a symbol(Package privat) static String
mapSharedLibraryName
(String libName) Similar toSystem.mapLibraryName(java.lang.String)
, except that it maps to standard shared library formats rather than specifically JNI formats.(Package privat) static String[]
matchFramework
(String libraryName) Look for a matching framework (OSX)(Package privat) static String
matchLibrary
(String libName, Collection<String> searchPath) matchLibrary() is very Linux specific.(Package privat) static double
parseVersion
(String ver) toString()
-
Methodendetails
-
matchFramework
Look for a matching framework (OSX) -
getInstance
Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned.More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.
- Parameter:
libraryName
- The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6"), or the full path to the library (e.g. "/lib/libc.so.6").
-
getInstance
Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned.More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.
- Parameter:
libraryName
- The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6"), or the full path to the library (e.g. "/lib/libc.so.6").classLoader
- The class loader to use to load the native library. This only affects library loading when the native library is included somewhere in the classpath, either bundled in a jar file or as a plain file within the classpath.
-
getInstance
Returns an instance of NativeLibrary for the specified name. The library is loaded if not already loaded. If already loaded, the existing instance is returned.More than one name may map to the same NativeLibrary instance; only a single instance will be provided for any given unique file path.
- Parameter:
libraryName
- The library name to load. This can be short form (e.g. "c"), an explicit version (e.g. "libc.so.6" or "QuickTime.framework/Versions/Current/QuickTime"), or the full (absolute) path to the library (e.g. "/lib/libc.so.6").libraryOptions
- Native library options for the given library (seeLibrary
).
-
getProcess
Returns an instance of NativeLibrary which refers to the current process. This is useful for accessing functions which were already mapped by some other mechanism, without having to reference or even know the exact name of the native library. -
getProcess
Returns an instance of NativeLibrary which refers to the current process. This is useful for accessing functions which were already mapped by some other mechanism, without having to reference or even know the exact name of the native library. -
addSearchPath
Add a path to search for the specified library, ahead of any system paths. This is similar to settingjna.library.path
, but only extends the search path for a single library.- Parameter:
libraryName
- The name of the library to use the path forpath
- The path to use when trying to load the library
-
getFunction
Create a newFunction
that is linked with a native function that follows the NativeLibrary's calling convention.The allocated instance represents a pointer to the named native function from the library.
- Parameter:
functionName
- Name of the native function to be linked with- Löst aus:
UnsatisfiedLinkError
- if the function is not found
-
getFunction
Create a newFunction
that is linked with a native function that follows the NativeLibrary's calling convention.The allocated instance represents a pointer to the named native function from the library.
- Parameter:
name
- Name of the native function to be linked with. Uses a function mapper option if one was provided to transform the name.method
- Method to which the native function is to be mapped- Löst aus:
UnsatisfiedLinkError
- if the function is not found
-
getFunction
Create a newFunction
that is linked with a native function that follows a given calling flags.- Parameter:
functionName
- Name of the native function to be linked withcallFlags
- Flags affecting the function invocation- Löst aus:
UnsatisfiedLinkError
- if the function is not found
-
getFunction
Create a newFunction
that is linked with a native function that follows a given calling flags.- Parameter:
functionName
- Name of the native function to be linked withcallFlags
- Flags affecting the function invocationencoding
- Encoding to use to convert between Java and native strings.- Löst aus:
UnsatisfiedLinkError
- if the function is not found
-
getOptions
- Gibt zurück:
- this native library instance's options.
-
getGlobalVariableAddress
Look up the given global variable within this library.- Parameter:
symbolName
-- Gibt zurück:
- Pointer representing the global variable address
- Löst aus:
UnsatisfiedLinkError
- if the symbol is not found
-
getSymbolAddress
Used by the Function class to locate a symbol- Löst aus:
UnsatisfiedLinkError
- if the symbol can't be found
-
toString
-
getName
Returns the simple name of this library. -
getFile
Returns the file on disk corresponding to this NativeLibrary instance. If this NativeLibrary represents the current process, this function will return null. -
disposeAll
static void disposeAll()Close all open native libraries. -
close
public void close()Close the native library we're mapped to.- Angegeben von:
close
in SchnittstelleAutoCloseable
- Angegeben von:
close
in SchnittstelleCloseable
-
dispose
Veraltet. -
matchLibrary
matchLibrary() is very Linux specific. It is here to deal with the case where /usr/lib/libc.so does not exist, or it is not a valid symlink to a versioned file (e.g. /lib/libc.so.6). -
parseVersion
-