![]() ![]() ![]() ![]() |
Using System Resources |
System provides two methods that allow your Java applications to load dynamic libraries:load()
andloadLibrary()
. Typically, your program will call one of these methods from within the static initializer of a class when you are working with native methods. See Integrating Native Methods into Java Programsfor information about writing native methods.
The
load()
method requires the complete path name of the library as an argument. For example, on a Solaris system you might write:to load theSystem.load("/home/me/libs/libmylib.so");libmylib.so
library in the/home/me/libs
directory.Using the
load()
method is system-dependent because it uses a pathname to load the library and pathnames are usually system-dependent. Thus,loadLibrary()
is sometimes a better choice. However, dynamically loadable libraries are system-dependent in nature so the use ofload()
may not compromise system-independence any more than the act of loading the library itself.The
loadLibrary()
method requires just the name of a library to load:TheSystem.loadLibrary("mylib");loadLibrary()
method searches for the library. The search performed byloadLibrary()
depends on the system you are running on, but typically, it searches the directories listed in one of your environment variables set up to that purpose. This is covered in detail in Integrating Native Methods into Java Programs.
Security consideration: Note that the ability to load dynamic libraries is subject to approval by the current security manager. When working with native methods, you must load dynamic libraries. So applets may not be able to use native methods depending on the browser or viewer they are running in. See Understanding Applet Capabilities and Restrictionsfor information about the security restrictions placed on applets.
![]() ![]() ![]() ![]() |
Using System Resources |