System.load () and System.loadlibrary () __java in Java

Source: Internet
Author: User

the difference between system.load () and System.loadlibrary ():

1. They can be used to load library files, either JNI or non-JNI library files. You must first load the corresponding JNI library file with one of the two methods before any local method is invoked.

2.system.load parameter is the absolute path of the library file

system.load () and System.loadlibrary () Detailed:

1. They can be used to load library files, either JNI or non-JNI library files. You must first load the corresponding JNI library file with one of the two methods before any local method is invoked.

The 2.system.load parameter is an absolute path to the library file, and can be any path.
Load a JNI library file under a Windows platform:
System.load ("D:\opencv\build\java\x64\opencv_java249.dll").

3. The system.loadlibrary parameter is the library filename and does not contain the extension of the library file.
Load a JNI library file under a Windows platform
System. LoadLibrary ("opencv_java249");

This is based on the premise that Opencv_java249.dll must be in the libraries of Java build path, and that the native library location in libraries is already configured. As shown in figure:


Or Opencv_java249.dll in the system's path variable, or Opencv_java249.dll in the path that the JVM variable Java.library.path points to.
You can obtain the value of the variable by:
System.getproperty ("Java.library.path");
By default, under the Windows platform, this value contains the following location:
1 Some directories related to JRE
2) Program Current directory
3) Windows directory
4) system catalog (SYSTEM32)
5 system environment variable path specified directory

4. If you want to load the library file link to other dynamic link library *.dll, then you must note:

1 If you choose System.load ("D:\opencv\build\java\x64\opencv_java249.dll"), then even if you put Pencv_java249.dll in the same D:\opencv\build\ Java\x64\, the load still fails because the dependent DLL is not found. Because the JVM is loading the opencv_java249.dll to load the dependent library file *.dll, *.dll is not located in the directory specified by Java.library.path, so the JVM cannot find *.dll.
You have two ways to solve this problem: one is to add D:\opencv\build\java\x64\ to the Java.library.path path, such as adding it to the system. Second, the first call
System.load ("D:\opencv\build\java\x64\*.dll"); Let the JVM load the *.dll first and then call System.load ("D:\opencv\build\java\x64\opencv_java249.dll");

2) If you choose
System. LoadLibrary ("opencv_java249");
Then you just put the *.dll in any java.library.path included path, and of course it includes the same directory as Opencv_java249.dll.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.