1. They can all be used to load library files, whether they are JNI library files or non-JNI library files. The corresponding JNI library file must be loaded using one of these two methods before any native method is called.
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 under the windows platform like this:
System.load("C://Documents and Settings//TestJNI.dll");.
3. The System.loadLibrary parameter is the library file name and does not include the extension of the library file.
For example, you can load a JNI library file under the windows platform like this
System. loadLibrary ("TestJNI");
Here, TestJNI.dll must be in the path pointed to by the jvm variable java.library.path.
The value of this variable can be obtained as follows:
System.getProperty("java.library.path");
By default, under Windows platforms, this value contains the following locations:
1) Some directories related to jre
2) Current directory of the program
3) Windows directory
4) System directory (system32)
5) The system environment variable path specifies the directory
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, then you must pay attention to:
1) If you choose
System.load("C://Documents and Settings// TestJNI.dll");
Then even if you put dependency.dll under C://Documents and Settings//, the load will still fail because the dependent dll cannot be found. Because when the jvm loads TestJNI.dll, it will first load the library file dependency.dll that TestJNI.dll depends on, and dependency.dll is not located in the directory specified by java.library.path, so the 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, add it to the system path. The second is to call first
System.load("C://Documents and Settings// dependency.dll"); Let the jvm load dependency.dll first, and then call System.load("C://Documents and Settings// TestJNI.dll" );
2) If you choose
System. loadLibrary ("TestJNI");
Then you just need to put dependency.dll in any path included in java.library.path, including the same directory as TestJNI.dll.