The order of references when multiple identical jars exist

Source: Internet
Author: User

Cause: Today an AAR package runs normally in a test environment, returns normally with the Soapui test, and runs in the local environment to keep the database connection exception checked because of a lack of OJDBC-related jar packages in the runtime environment.

Re-hit an AAR package and put the OJDBC into the AAR to run normally.

This has aroused my great interest in why the same AAR does not need to be added to Ojdbc in AAR in the test environment to function properly?

Finally find the answer here:

Java Virtual machine class loading order (as commented, the text written in the "system ClassLoader" a bit misleading, should be changed to "Appclassloader", more convenient to understand, that is, the application of the ClassLoader)

1. Check if this class is loaded (that is, if there is this class in the cache), if there is 8, if not to 2
2. If the parent ClassLoader does not exist (without the parent, the parent must be bootstrap ClassLoader), to 4
3. Request the parent ClassLoader to load, if successful to 8, unsuccessful to 5
4. Request that the JVM be loaded from bootstrap ClassLoader if successful to 8
5. Look for the class file (from the classpath associated with this classloader). If not found then to 7.
6. Load class from file to 8.
7. Throw classnotfoundexception.
8. Return to class.

load order of class and jar in Tomcat

By ClassLoader's parent-to-child delegate mode loading mechanism we know that assuming that two package names and class names are the same as the same jar package, if a class file is already loaded in the Java virtual machine, then the same class file will not be loaded later.

Then the following tests were made:

            New oracle.jdbc.driver.OracleDriver (); //             oracledriver od = new Oracledriver ();            String DBPath = Java.net.URLDecoder.decode (Od.getclass (). Getprotectiondomain (). Getcodesource (). GetLocation (). ToString (), "UTF-8");            Commlogger.printlog ("oracledriver path" + Od.getclass (). Getprotectiondomain (). Getcodesource (). GetLocation ());            Commlogger.printlog ("DBPath" +dbpath);

Get the path to the Oracledriver class.

1. Add Ojdbc.jar under Tomcat/lib.

2. Add Ojdbc.jar under Axis2/web-inf/lib.

3. Add Ojdbc.jar to the packaged AAR.

Condition 1 only, the output is as follows:

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/lib/ojdbc14.jar

Condition 2 only, the output is as follows:

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/webapps/axis2/web-inf/lib/ojdbc14.jar

Condition 3 only, the output is as follows:

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/temp/axis2-tmp-8189257264145727421.tmp/ Axis24403210224279191362ojdbc14.jar

Conditions 1 and 2, as follows

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/webapps/axis2/web-inf/lib/ojdbc14.jar

Conditions 1 and 3, as follows

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/lib/ojdbc14.jar

Conditions 2 and 3, as follows

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/webapps/axis2/web-inf/lib/ojdbc14.jar

Condition 123 is added as follows

DBPath file:/c:/program files/apache Software foundation/tomcat 7.0/webapps/axis2/web-inf/lib/ojdbc14.jar

The order of references when multiple identical jars exist

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.