class loading in tomcat on demand when 2 versions of a lib are present?


class loading in tomcat on demand when 2 versions of a lib are present?



I was searching about this with many sources from the internet. But still I couldn't find a specific resource which exactly addresses my question.



In tomcat, is there any order in classes are loaded at startup. Just imagine a situation like this.



I have myApp.war file inside webapps. And inside that war, I have some library (say mylib-2.5.jar bundled inside it). And imagine, I have also placed the same library in different version (say mylib-2.8.jar) inside the /lib folder.



So when I start up my application, and call a particular end point, which lib (version) will have the chance to be loaded (on demand) into JVM by a class loader?



And what are the chances for a lib conflict? and what are the reason for that?





Whats wrong with tomcat.apache.org/tomcat-8.0-doc/class-loader-howto.html ?
– Gyro Gearless
Jul 2 at 13:17





@GyroGearless It doesn't have ans about the conflict. may be my question title is wrong. :))
– Supun Wijerathne
Jul 2 at 13:22





@GyroGearless question edited. :))
– Supun Wijerathne
Jul 2 at 13:24





Possible duplicate of Order of loading jar files from lib directory
– Eugène Adell
Jul 2 at 15:21




1 Answer
1



From link posted by @GyroGearless



Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:



•Bootstrap classes of your JVM



•/WEB-INF/classes of your web application



•/WEB-INF/lib/*.jar of your web application



•System class loader classes (described above)



•Common class loader classes (described above)



If the web application class loader is configured with <Loader delegate="true"/> then the order becomes:


<Loader delegate="true"/>



•Bootstrap classes of your JVM



•System class loader classes (described above)



•Common class loader classes (described above)



•/WEB-INF/classes of your web application



•/WEB-INF/lib/*.jar of your web application



If classloader needs to load class X then once it finds it in one place it will not look for it in any other places.
Lib conflict is possible if you place one version of your dependency (say MySQL driver) to $JAVA_HOME/jre/lib/ext and another one into /WEB-INF/lib


MySQL


$JAVA_HOME/jre/lib/ext


/WEB-INF/lib






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages