Hi,

Thanks very much for confirming that and for providing me with more 
information. One thing I still find strange though is how SupplementaryEdit (in 
the webapp) is able to call a class loaded by the "common" classloader? Does it 
not work the other way round as well?

Thanks,

Paul

-----Original Message-----
From: Shay Rojansky [mailto:r...@roji.org]
Sent: 28 June 2010 13:35
To: Tomcat Users List
Subject: Re: Classloading

Hi Paul.

Yes, this is the normal behavior. As you found out, Tomcat uses a different
classloader for the "common" classes than that used for for loading your
webapp classes.

Basically, when your application loads PracCalc, Tomcat looks first in the
"common" directory and loads it from there. Then, since the reference to
SupplementaryEdit is from PracCalc, PracCalc's classloader (the "common"
one) is used to search for the dependency, SupplementaryEdit. Since the
"common" classloader knows nothing about your webapp's classes, a
ClassNotFoundException is thrown.

You have to plan well how to manage your JARs and classes. One solution is
to put all dependencies in your webapp, another is to make sure that if you
put a dependency in Tomcat's common directory, all of the dependency's
dependencies must also be there.

Shay

On Mon, Jun 28, 2010 at 8:22 AM, Ockleford Paul (NHS Connecting for Health)
<paul.ocklef...@nhs.net> wrote:

> Hi,
>
> I had a problem this morning that took me a while to sort out, and now I
> know what the issue is I was hoping somebody could explain why the problem
> was happening. I assume it is because one class had been loaded by a
> different classloader, and so wasn't available to the second class.
>
> I have 2 classes in different packages but within the same web application:
>
> SupplementaryEdit - webapps/WEB-INF/classes
> PracCalc - webapps/WEB-INF/classes
>
> I added a method to SupplementaryEdit and then called it within this class
> and it worked ok. Next I created an object of SupplementaryEdit in PracCalc
> and tried to call this new method. I got a classnotfoundexception for
> SupplementaryEdit at the point of instantiation and I was struggling to find
> out why.
>
> After spending ages trying different things I started looking through the
> common classes in tomcat and found that someone had previously created a
> symlink to the package PracCalc is in there. I read a little on tomcat
> classloading and came to the conclusion that this was causing PracCalc to be
> loaded by a different loader to SupplementaryEdit.
>
> If someone could confirm this that would be good, and also could someone
> explain why the class in the web app isn't available to the class referenced
> in common/lib?
>
> I don't understand because I get a runtime exception in the block where the
> object is created, and not on initial class use (as I used the class without
> triggering the code block fine), and I also don't understand why at runtime
> the common classloader is not able to resolve the class, as I have tested by
> calling a class that creates a SupplementaryEdit object before trying from
> PracCalc and it still didn't work.
>
> To resolve the issue I moved the method into PracCalc as this still made
> sense logically and the code now works, just looking for some general
> help\guidance.
>
> Thanks,
>
> Paul
>
>
> ********************************************************************************************************************
>
> This message may contain confidential information. If you are not the
> intended recipient please inform the
> sender that you have received the message in error before deleting it.
> Please do not disclose, copy or distribute information in this e-mail or
> take any action in reliance on its contents:
> to do so is strictly prohibited and may be unlawful.
>
> Thank you for your co-operation.
>
> NHSmail is the secure email and directory service available for all NHS
> staff in England and Scotland
> NHSmail is approved for exchanging patient data and other sensitive
> information with NHSmail and GSI recipients
> NHSmail provides an email address for your career in the NHS and can be
> accessed anywhere
> For more information and to find out how you can switch, visit
> www.connectingforhealth.nhs.uk/nhsmail
>
>
> ********************************************************************************************************************
>

********************************************************************************************************************

This message may contain confidential information. If you are not the intended 
recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take 
any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff 
in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information 
with NHSmail and GSI recipients
NHSmail provides an email address for your career in the NHS and can be 
accessed anywhere
For more information and to find out how you can switch, visit 
www.connectingforhealth.nhs.uk/nhsmail

********************************************************************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to