![]() ![]() ![]() ![]() |
Using System Resources |
System provides two methods that allow your Java applications to load dynamic libraries:load()
andloadLibrary()
.
Note: Applets are not allowed to load dynamic libraries. A call to eitherload()
orloadLibrary()
from within an applet will result in a SecurityException.
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 Programs
for 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 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.
![]() ![]() ![]() ![]() |
Using System Resources |