Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Order in which class is searched

 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What is the order in which a class is searched...in a web application deployed

like say...lib folder,classes folder,jdk ext folder..etc..

Tx in advance,
Regards
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems to me that this is the type of question that would be answered by looking at the Servlets Specification. (Hint: chapter 9)

Originally posted by A Kumar:
Tx in advance,



Texas in advance?
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The Servlet Spec can't spell out the whole story since there are container-specific nuances as well. So you'll need to check out the docs for your container as well.
 
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually this is the order
1. Bootstrap classes like java.lang.String
2. Classes in java.ext.dirs
3. System classpath defined by CLASSPATH
4. AppServer libraries inside of some lib folder
5. For web app - lib folder first and then the classes folder.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your application server class loader hierachy.

Also the delegation mode(delegating it to parent class loader) which you can turn on and off.

J2EE Spec should have a standard class loading hierachy as mentioned by Prabhat, but application server vendors may have a more specialized implementation for example JBoss application server uses a UnifiedClassLoader.


Excerpt from Java/J2EE Job Interview Companiondiagram is missing as i could not paste it.




The J2EE application specific class loaders are children of the �System �classpath� class loader. When the parent class loader is above the �System �Classpath� class loader in the hierarchy as shown in the diagram (i.e. bootstrap class loader or extensions class loader) then child class loaders implicitly have visibility to the classes loaded by its parents. When a parent class loader is below a �System -Classpath� class loader then the child class loaders will only have visibility into the classes loaded by its parents only if they are explicitly specified in a manifest file (MANIFEST.MF) of the child class loader.

Example As per the diagram, if the EJB module MyAppsEJB.jar wants to refer to MyAppsCommon.jar and MyAppsUtil.jar we need to add the following entry in the MyAppsEJB.jar�s manifest file MANIFEST.MF.

class-path: MyAppsCommon.jar MyAppsUtil.jar



This is because the application (EAR) class loader loads the MyAppsCommon.jar and MyAppsUtil.jar. The EJB class loader loads the MyAppsEJB.jar, which is the child class loader of the application class loader. The WAR class loader loads the MyAppsWeb.war.

Every J2EE application or EAR gets its own instance of the application class loader. This class loader is responsible for loading all the dependency jar files, which are shared by both WEB and EJB modules. For example third party libraries like log4j, utility classes, shared classes or common classes (Exception thrown by an EJB module should be caught by a WEB module) etc.

The key difference between the EJB and WAR class loader is that all the EJB jars in the application share the same EJB class loader whereas WAR files get their own class loader. This is because the EJBs have inherent relationship between one another (ie EJB-EJB communication between EJBs in different applications but hosted on the same JVM) but the Web modules do not. Every WAR file should be able to have its own WEB-INF/lib third party libraries and need to be able to load its own version of converted logon.jsp Servlet so each WEB module is isolated in its own class loader.

So if two different WEB modules want to use two different versions of the same EJB then we need to have two different ear files. As was discussed in the Q4 in Java section the class loaders use a delegation model where the child class loaders delegate the loading up the hierarchy to their parent before trying to load it itself only if the parent can�t load it. But with regards to WAR class loaders, some application servers provide a setting to turn this behaviour off (DelegationMode=false). This delegation mode is recommended in the Servlet 2.3 specification.

As a general rule classes should not be deployed higher in the hierarchy than they are supposed to exist. This is because if you move one class up the hierarchy then you will have to move other classes up the hierarchy as well. This is because classes loaded by the parent class loader can�t see the classes loaded by its child class loaders (uni-directional bottom-up visibility).

[ July 07, 2006: Message edited by: ak pillai ]
[ July 07, 2006: Message edited by: ak pillai ]
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Pradip Bhat:
Usually this is the order
1. Bootstrap classes like java.lang.String
2. Classes in java.ext.dirs
3. System classpath defined by CLASSPATH
4. AppServer libraries inside of some lib folder
5. For web app - lib folder first and then the classes folder.



Sorry, but most of that is incorrect. The WEB-INF/classes folder will always take precedence over jars in WEB-INF/lib, and the app-local classes take precendence over container-defined folders.

Again, refer to the Servlet Specification and your container documentation for precise details.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks all !!!

Hi Bear ..can you reorder the list which is generally followed?

Regards
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the section of the Servlet Spec that I mentioned?
 
Pradeep bhatt
Ranch Hand
Posts: 8943
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


Sorry, but most of that is incorrect. The WEB-INF/classes folder will always take precedence over jars in WEB-INF/lib, and the app-local classes take precendence over container-defined folders.

Again, refer to the Servlet Specification and your container documentation for precise details.



I agree that classes in WEB-INF/classes are loaded before WEB-INF/lib folder. For Webspshere the order as I mentioned holds good.
http://publib.boulder.ibm.com/infocenter/wasinfo/v5r0/topic/com.ibm.websphere.base.doc/info/aes/ae/crun_classload.html
 
I am Arthur, King of the Britons. And this is a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic