Java System. Load and system. loadlibrary

Source: Internet
Author: User

      1. These two functions load and link dynamic libraries through the specified path, for example, the *. dll file generated by C and C ++ compilation in JNI.
      2. Public static void load (string pathname)Function, parameterPathnameIs an absolute path, for example: system. Load ("E:/test. dll ");
      Suffix.
      3. Public static void loadlibrary (string libname). The parameter is the name of the dynamic library and has no suffix. The system automatically determines the parameter. So where should the library files be stored.
      It should be placed in the path pointed to by the JVM variable java. Library. Path.
      You can get this path through: system. getproperty ("Java. Library. Path. You can alsoProgramThe current directory. You can use: system. getproperty ("user. dir"); to obtain the current directory of the program.
      You can also set the JVM variable java. Library. Path:
      Right-click your Java project, choose Properties> JAVA build path> source> native library location> edit, and set it to the path you want, copy the library file to it and you will be OK. Of course, you can only store the loaded dynamic library in this path. You can also right-click SRC to set the native library of its attributes. The two are set to the same variable.
      4. If the library file you want to load is statically linked to other dynamic link libraries, such as testjni. dll, which is statically linked to dependency. dll, note the following:
      Because the JVM is loading testjni. the dll will first load testjni. the library file dependency that the DLL depends on. DLL, if both use system. load, load dependency first. DLL, and then load testjni. DLL.
      Conclusion: We recommend that you use system. loadlibrary and set java. Library. path by yourself.

      Reference: http://blog.csdn.net/forandever/article/details/5983846


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.