Java Dynamic Management Kit 3.2 Programming Guide | ||||
---|---|---|---|---|
![]() | ![]() | Chapter 12. Dynamic Loading Services | ![]() | ![]() |
The library loader loads native libraries into the framework. The Java Dynamic Management Kit enables native libraries and m-beans to be loaded from the same remote server. A native library is loaded whenever a new m-bean class that includes native code is loaded. For information on how to implement an m-bean that includes native code, refer to Including Native Code in an M-Bean.
When the System.loadLibrary() method is invoked, it performs one of the following actions:
If the class loader that loaded the class can also act as a native library loader, that is, it implements the java.lang.ClassLoader.findLibrary() method, this method is invoked to load the native library.
If the class loader cannot act as a native library loader, that is, does not implement the java.lang.ClassLoader.findLibrary() method, the Java virtual machine searches for the library along the path specified by the java.library.path property.
The library loaded depends on the hardware platform and operating system on which the library will run. For more information, refer to Location of Native Libraries. The native library can be loaded from the local file system or a remote server.
The Java Dynamic Management Kit allows an agent to load only dynamic native libraries (.dll for Windows, .so for Solaris). An agent is not allowed to load static native libraries.
To enable an m-bean to use a native library, include in the m-bean a call to the static loadLibrary() method of the System class. Example 12-1 shows the signature for the System.loadLibrary() method.
Example 12-1. Signature for the System.loadLibrary method
public static void loadLibrary(String libname) |
Example 12-2 shows the code to include in an m-bean to use the library loader service of the Java Dynamic Management Kit.
Example 12-2. Including Native Code in an M-Bean
public KernelStat(String mod, String inst) { moduleName = mod; instanceName = inst; System.loadLibrary("stat"); } |
The java.lang.ClassLoader.findLibrary() method "is aware" of the location of native libraries. The method initially searches for the library using only the native library name. Then the method searches using the native library name and the architecture-dependent location. This location depends on the operating system and architecture of the machine on which the library will run. The architecture-dependent location relative to the library base path is:
OSName/OSArch/OSVersion/lib/libraryName |
The variable parts of this location are:
OSName
The name of the operating system under which the native library will run.
OSArch
The name of the processor architecture of the machine on which the library will run.
OSVersion
The version number of the operating system under which the native library will run.
libraryName
The name of the file that contains the native library. The file name extension depends on the specified operating system (.dll for Windows, .so for Solaris).
For example, the location of the stat native library for the SolarisTM 7 operating environment for a Solaris SPARCTM processor would be as follows:
SunOS/sparc/5.7/lib/libstat.so |
The stat native library for the Windows NT 4.0 operating system for an x86 processor would be:
WindowsNT\x86\4.0\lib\stat.dll |
![]() | ![]() | ![]() |
Class Loaders | ![]() | Security Manager |