Black magic, of course...but slowly I'm going to understand how to handle
that and to become a magician :-) Thanx ! 
Oliver

> AXA eSolutions GmbH
> AXA Konzern AG Germany
> Oliver Lauer 
> Web Architect
> W�rthstra�e 34
> D-50668 K�ln
> Germany
> Tel.: +49 221 148 31277
> Fax: +49 221 148 43963
> Mobil: +49 179 59 064 59
> e-Mail: [EMAIL PROTECTED]
> _____________________________
> 


-----Urspr�ngliche Nachricht-----
Von: Bo Xu [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 17. Dezember 2001 21:22
An: Tomcat Users List
Betreff: Re: AW: Classloader question


----- Original Message -----
From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Monday, December 17, 2001 1:51 PM
Subject: Re: AW: Classloader question


On Mon, 17 Dec 2001, Lauer, Oliver wrote:

>
> But why wasn't the class found in myapp/WEB-INF/lib ? Sorry, but I don't
> understand that !?
>

Class loaders are black magic :-).  Here is one simple scenario to
illustrate the kinds of problems you can have.

Assume you have class A that uses Class.forName() to dynamically create
classes for you.  Now assume that class A is in /common/lib, and you pass
it the name of a class that is present only in /WEB-INF/lib to create.
Because A was loaded from the "Common" classloader, it cannot see classes
in your webapp, and you get ClassNotFoundException.

As another example of problems you can encounter, assume you have classes
A and B in a JAR file, and that you have that JAR file in both
/WEB-INF/lib of your webapp, and in /common/lib.  Assume that class A has
a method foo that takes a B as a parameter.  Now, consider the following
sequence of events:

* Class A gets loaded from /common/lib (because it was
  first referenced by some other class in /common/lib.

* You create an instance of class A and store it in your
  session attributes.

* Class B gets loaded from /WEB-INF/lib (because it was
  first referenced by some other class in /WEB-INF/lib.

* You create a local instance of class B.

* Your application retrieves the A object from the session
  attributes and tries to call foo(), passing the instance
  of B mentioned above.

* You get a ClassCastException error.

Why?  Because the instance of class A (loaded from /common/lib) can only
accept an argument that is an instance of class B *also* loaded from
/common/lib).  The class B loaded from /WEB-INF/lib is considered to be a
different class, even though it has the same name (and perhaps even the
same bytes).

There are thousands of ways you can trip yourself up like this.  In
general, you're much better off ensuring that you have one and only one
copy of every class visible -- then, you never have to worry about it.

Craig



Hello Craig,  Thanks for your email !   I have a question about ClassLoaders
in TOMCAT4.0,    is the following right?
-way1   for some kinds of classes(for ex., java.lang.String), the
ClassLoader of
             mywebapp will follow the normal ClassLoader Delegation Model

-way2   but for other classes(for ex., MySerlvet.class), the ClassLoader of
mywebapp
            will "partly-follow" the normal ClassLoader Delegation Model ,
i.e., it will first look
             for the class in WEB-INF/classes and WEB-INF/lib, if it is not
there, then goto
             the normal  ClassLoader Hierarchies(Primordial
ClassLoader/System ClassLoader...)

-way3   or for any class, the ClassLoader of mywebapp will follow the way2?

- other ClassLoaders( for server/classes|server/lib,
common/classes|common/lib,
   shared/classes|shared/lib) will completely-follow the normal ClassLoader
   Delegation Model, is that right?

Thanks in advance!

Bo
Dec.17, 2001



--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>


------------------------------------------------------------------------------
Aus Rechts- und Sicherheitsgruenden ist die in dieser E-Mail gegebene Information 
nicht rechtsverbindlich. Eine rechtsverbindliche Bestaetigung reichen wir Ihnen gerne 
auf Anforderung in schriftlicher Form nach. Beachten Sie bitte, dass jede Form der 
unautorisierten Nutzung, Veroeffentlichung, Vervielfaeltigung oder Weitergabe des 
Inhalts dieser E-Mail nicht gestattet ist.Diese Nachricht  ist ausschliesslich fuer 
den bezeichneten Adressaten oder dessen Vertreter bestimmt. Sollten Sie nicht der 
vorgesehene Adressat dieser E-Mail oder dessen Vertreter sein, so bitten wir Sie, sich 
mit dem Absender der E-Mail in Verbindung zu setzen.
----------------------------
For legal and security reasons the information provided in this e-mail is not legally 
binding. Upon request we would be pleased to provide you with a legally binding 
confirmation in written form. Any form of unauthorised use, publication, reproduction, 
copying or disclosure of the content of this e-mail is not permitted. This message is 
exclusively for the person addressed or their representative. If you are not the 
intended recipient of this message and its contents, please notify the sender 
immediately.

==============================================================================


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to