1. They can all be used to load library files, whether JNI library files or non-JNI library files. Before calling any local method, you must first load the corresponding JNI library file with one of the two methods.
2. The system. Load parameter is the absolute path of the library file, which can be any path.
For example, you can load a JNI library file on Windows:
System. Load ("C: \ Documents and Settings \ testjni. dll ");.
3. The system. loadlibrary parameter is the library file name and does not contain the library file extension.
For example, you can load a JNI library file on Windows.
System. loadlibrary ("testjni ");
Here, testjni. dll must be in the path pointed to by the JVM variable java. Library. Path.
You can use the following method to obtain the value of this variable:
System. getproperty ("Java. Library. Path ");
By default, on Windows, this value contains the following locations:
1) Some JRE-related directories
2) current program directory
3) Windows Directory
4) system directory (system32)
5) Specify the directory in the path of the system environment variable
4. If the library file you want to load is statically linked to other dynamic link libraries, for example, testjni. dll is statically linked to dependency. dll, you must note:
1) if you choose
System. Load ("C: \ Documents and Settings \ testjni. dll ");
Even if you put dependency. dll under c: \ Program ents and Settings \, load will still fail because the dependent DLL cannot be found. Because the JVM is loading testjni. the dll will first load testjni. the library file dependency that the DLL depends on. DLL, and dependency. DLL is not in Java. library. directory specified by path, so JVM cannot find dependency. DLL.
You have two ways to solve this problem: first, add c: \ Documents and Settings \ to the path of Java. Library. path, for example, to the path of the system. Second, call
System. load ("C: \ Documents ents and Settings \ dependency. DLL "); let the JVM first load dependency. DLL, and then call system. load ("C: \ Documents ents and Settings \ testjni. DLL ");
2) If you choose
System. loadlibrary ("testjni ");
You only need to put dependency. dll in any path contained in Java. Library. path, including the same directory as testjni. dll.
For Linux/Unix systems, there is only one difference
1. system. Load ("C: \ Documents ents and Settings \ testjni. dll"); same as windows
2. system. loadlibrary ("testjni ")
Testjni. dll must be named in Linux/UnixLibTestjni. So
Java-djava. Library. Path =.