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.
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.
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 ]
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.
Joined: Jul 04, 2004
Thanks all !!!
Hi Bear ..can you reorder the list which is generally followed?