Solve the problem of "java.lang.UnsatisfiedLinkError:Native Library. dll already loaded in another ClassLoader"

Source: Internet
Author: User

After Java is started, the classes are loaded into memory by the JVM level ClassLoader. To better understand the loading process, I analyze and write a simple classloader to analyze its principle.

The ClassLoader of the JVM is divided into three layers, respectively, bootstrap classloader,extension Classloader,system ClassLoader, they are not the parent-child relationship of class inheritance, and are the logical upper and subordinate relations.

Bootstrap ClassLoader is a startup class loader that is written in C + +, loads a class from the%jre%/lib directory, or is loaded with the-xbootclasspath specified directory at run time.

Extension ClassLoader is an extension class loader that loads classes from the%jre%/lib/ext directory, or when the runtime uses-djava.ext.dirs to develop a directory.

System ClassLoader, which will find the path from the classpath of the system environment variable configuration, in the environment variable. Represents the current directory, which is loaded by the runtime-classpath or-djava.class.path the specified directory to load the class.

You can enter the load path for each ClassLoader that is now loaded by using the following three statements:

System. out. println ("Sun.boot.class.path:" + System. GetProperty("Sun.boot.class.path"));

System. out. println ("Java.ext.dirs:" + System. GetProperty("Java.ext.dirs"));

System. out. println ("Java.class.path:" +system. GetProperty("Java.class.path"));

1 Sun.boot.class.path:2C:\D\programsoft\Java\jre1.8. 0_45\lib\resources.jar;3C:\D\programsoft\Java\jre1.8. 0_45\lib\rt.jar;4C:\D\programsoft\Java\jre1.8. 0_45\lib\sunrsasign.jar;5C:\D\programsoft\Java\jre1.8. 0_45\lib\jsse.jar;6C:\D\programsoft\Java\jre1.8. 0_45\lib\jce.jar;7C:\D\programsoft\Java\jre1.8. 0_45\lib\charsets.jar;8C:\D\programsoft\Java\jre1.8. 0_45\lib\jfr.jar;9C:\D\programsoft\Java\jre1.8. 0_45\classesTen  One Java.ext.dirs: AC:\D\programsoft\Java\jre1.8. 0_45\lib\ext; - C:\WINDOWS\Sun\Java\lib\ext -  the Java.class.path: - C:\Users\Mat lei\workspace\flexandjava_server\build\classes; -C:\D\basic\programsoft\Tomcat 8.0\lib\annotations-Api.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\catalina-Ant.jar; +C:\D\basic\programsoft\Tomcat 8.0\lib\catalina-Ha.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\catalina-Storeconfig.jar; +C:\D\basic\programsoft\Tomcat 8.0\lib\catalina-Tribes.jar; AC:\D\basic\programsoft\Tomcat 8.0\lib\catalina.jar; atC:\D\basic\programsoft\Tomcat 8.0\lib\ecj-4.4.2. jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\el-Api.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\jasper-El.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\jasper.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\jsp-Api.jar; -C:\D\basic\programsoft\Tomcat 8.0\lib\servlet-api.jar;

First access to project A's interface, the interface called Appleta, and then did not close the browser and directly access to Project B interface, in the interface called APPLETB. Appleta and Appletb are actually the same applet, except that the applet is used in two projects, and two projects are accessed directly. At this time, when accessing the APPLETB, there will be an error:

XXX not loaded java.lang.UnsatisfiedLinkError:Native Library XXX.dll already loaded in another ClassLoader

If access is from APPLETB to Appleta, the same error will occur when accessing Appleta.
Because, in a single tab, multiple applets run in fact run on the same JVM, but use different classloader when loading applets. Therefore, whether the Appleta run first or Appletb first, the final situation is that the DLLs you rely on will be loaded by the same JVM, and the above error will occur.

After Google, many developers have encountered the same problem, either because in the same Java EE container (weblogic,jboss) deployed two to access the same JNI invocation of the project, and some are like the author of the same experience. The final conclusion is that in a JVM, it is not allowed to load a DLL two times. Therefore, when the subsequent JNI call attempts to load the same DLL again, the above error is reported. Because of this error, the corresponding Java class must not be initialized, so the project or applet must not start.

The workaround is to copy the jar that calls the DLL to C:\D\programsoft\Java\jre1.8.0_45\lib, which is the bootstrap ClassLoader loaded directory and add the jar under the JRE System Library , and in

The jar is selected in the JRE System library--properties--installed jres--edit--add External jars. The jar can be loaded in bootstrap classloader and is not subject to threading restrictions.

Reference content:

Http://www.cnblogs.com/newstar/archive/2012/03/14/2396176.html

Http://www.cnblogs.com/Lawson/archive/2012/07/31/2616623.html

Solve the problem of "java.lang.UnsatisfiedLinkError:Native Library. dll already loaded in another ClassLoader"

Related Article

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.