You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Ockleford Paul (NHS Connecting for Health)" <pa...@nhs.net> on 2010/06/28 14:22:16 UTC

Classloading

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

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

Re: Classloading

Posted by Pid <pi...@pidster.com>.
On 28/06/2010 14:14, Peter Crowther wrote:
> On 28 June 2010 14:07, Ockleford Paul (NHS Connecting for Health) <
> paul.ockleford@nhs.net> wrote:
> 
>> Pretty much and I don't know the reason why that is, I am not in charge of
>> the linux servers I only started looking into it because I couldn't get my
>> method to work but it worked on my local windows environment. The entire web
>> app is classes so its actually a class in WEB-INF\classes, that for some
>> unknown reason the entire package is also sym linked in
>> tomcat\common\classes.
>>
>> Can you think of any reason why someone would do that? I can only assume
>> that at some point in the past someone else has had classloading issues and
>> decided that that hack would solve it. That is unconfirmed though.
>>
> Another option would be if two different webapps "need" to share static
> variables (such as a singleton) in a common class.  At that point, the
> common class must only be loaded once, so must be in common (or higher).

... all of which means that you have a broken & fragile Tomcat.

The same class may not be in two places in the classloader tree.  As
you've discovered, someone botched a fix and stored up a problem for
someone else to find later.

I strongly recommend that you examine what's happening and remove the
symlink(s).  Either put the classes in the common classloader, or put
them in the web app - but not both.


p




Re: Classloading

Posted by Peter Crowther <pe...@melandra.com>.
On 28 June 2010 14:07, Ockleford Paul (NHS Connecting for Health) <
paul.ockleford@nhs.net> wrote:

> Pretty much and I don't know the reason why that is, I am not in charge of
> the linux servers I only started looking into it because I couldn't get my
> method to work but it worked on my local windows environment. The entire web
> app is classes so its actually a class in WEB-INF\classes, that for some
> unknown reason the entire package is also sym linked in
> tomcat\common\classes.
>
> Can you think of any reason why someone would do that? I can only assume
> that at some point in the past someone else has had classloading issues and
> decided that that hack would solve it. That is unconfirmed though.
>
> Another option would be if two different webapps "need" to share static
variables (such as a singleton) in a common class.  At that point, the
common class must only be loaded once, so must be in common (or higher).

- Peter

RE: Classloading

Posted by "Ockleford Paul (NHS Connecting for Health)" <pa...@nhs.net>.
Pretty much and I don't know the reason why that is, I am not in charge of the linux servers I only started looking into it because I couldn't get my method to work but it worked on my local windows environment. The entire web app is classes so its actually a class in WEB-INF\classes, that for some unknown reason the entire package is also sym linked in tomcat\common\classes.

Can you think of any reason why someone would do that? I can only assume that at some point in the past someone else has had classloading issues and decided that that hack would solve it. That is unconfirmed though.

Paul


-----Original Message-----
From: Pid [mailto:pid@pidster.com]
Sent: 28 June 2010 14:02
To: Tomcat Users List
Subject: Re: Classloading

On 28/06/2010 13:48, Ockleford Paul (NHS Connecting for Health) wrote:
> 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?

So, to clarify something, there is a symlink in common/lib which points to a jar which is actually inside your application WEB-INF/lib?


p


> Thanks,
>
> Paul
>
> -----Original Message-----
> From: Shay Rojansky [mailto:roji@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) <pa...@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>



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

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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Classloading

Posted by Pid <pi...@pidster.com>.
On 28/06/2010 13:48, Ockleford Paul (NHS Connecting for Health) wrote:
> 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?

So, to clarify something, there is a symlink in common/lib which points
to a jar which is actually inside your application WEB-INF/lib?


p


> Thanks,
> 
> Paul
> 
> -----Original Message-----
> From: Shay Rojansky [mailto:roji@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)
> <pa...@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 



RE: Webapp reloading issue and intermittent 404 errors

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Tomislav Petrović [mailto:t.petrovic@inet.hr]
> Subject: Webapp reloading issue and intermittent 404 errors
> 
> Tomcat is: Apache Tomcat/6.0.24, Java is 6 don't know update number
> exactly but can find out if necessary.

Try moving to 6.0.26, or 6.0.27 when it comes out in a few days.  The exact JVM version may be useful.

> Seems to me it is related to web app reloading but this 
> is my blind guess.

What makes you suspicious that reloading is going on?

Have you checked the timestamps of the .war file against the system clock?  Times in the future have been known to trigger reload loops and other errors (perhaps your 404).

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


Re: Webapp reloading issue and intermittent 404 errors

Posted by Pid <pi...@pidster.com>.
On 28/06/2010 14:25, Tomislav Petrović wrote:
> I have two problems with a fairly complex webapp. I don't know if they
> are related or not.
> Webapp has been deployed on several dozens of customers without problem
> and tested in our lab on several configurations without problem.
> 
> However one customer has following two issues.
> Tomcat is: Apache Tomcat/6.0.24, Java is 6 don't know update number
> exactly but can find out if necessary.
> 
> First...
> In catalina*.log log files we get exceptions with following stacktrace
> (on a load test we get a lot of them, on normal run we get something
> like one/two per hour):
> 
> Jun 21, 2010 1:17:21 PM org.apache.catalina.core.ContainerBase
> backgroundProcess
> WARNING: Exception processing loader WebappLoader[/hidden_name] background process
> java.lang.StringIndexOutOfBoundsException: String index out of range: 110
> 	at java.lang.String.substring(String.java:1934)
> 	at org.apache.catalina.util.RequestUtil.normalize(RequestUtil.java:131)
> 	at org.apache.naming.resources.FileDirContext.normalize(FileDirContext.java:771)
> 	at org.apache.naming.resources.FileDirContext.file(FileDirContext.java:811)
> 	at org.apache.naming.resources.FileDirContext.getAttributes(FileDirContext.java:429)
> 	at org.apache.naming.resources.BaseDirContext.getAttributes(BaseDirContext.java:747)
> 	at org.apache.naming.resources.ProxyDirContext.getAttributes(ProxyDirContext.java:840)
> 	at org.apache.catalina.loader.WebappClassLoader.modified(WebappClassLoader.java:822)
> 	at org.apache.catalina.loader.WebappLoader.modified(WebappLoader.java:477)
> 	at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:398)
> 	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309)
> 	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
> 	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
> 	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
> 	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
> 	at java.lang.Thread.run(Thread.java:619)
> 
> 
> Actual index in "String index out of range: " varies with every occurrence.
> 
> What could be causing this? 
> Seems to me it is related to web app reloading but this is my blind guess. 
> What I know is that app should not be automatically reloaded (nothing 
> changes in WEB-INF/* folders) nor is "told" to reload via Tomcat manager.
> So please help! :)
> 
> Second one...
> Don't know if it is related to first one or separate issue. 
> From time to time on a load test we get intermittent 404 errors 
> on our jsp pages. "Intermittent" meaning page gives 404 error on a request 
> and randomly and next request to a same page goes ok (few miliseconds
> later). 
> What I know is that:
> 1. JSP page exists for certain (it is not moved or deleted or anything) 
> works ok before it happens, works ok afterwards
> 2. All JSPs are written in a way that they don't throw any exceptions to 
> the outside (surrounded in try/catch everything). If/when code 
> invoked inside throws unhandled exception page will produce some custom 
> error message inside enclosing catch.
> 
> What could be causing this? Is it related to first problem, or a 
> completely new one?
> 
> Thanks for any info you can provide me,


Please start an entirely new email, don't just edit a reply to an
existing thread (you don't remove the mail thread id header by just
editing the subject/body, so your message appears in the middle of
someone elses thread).  This is called 'thread-hijacking'.


p



Webapp reloading issue and intermittent 404 errors

Posted by Tomislav Petrović <t....@inet.hr>.
I have two problems with a fairly complex webapp. I don't know if they
are related or not.
Webapp has been deployed on several dozens of customers without problem
and tested in our lab on several configurations without problem.

However one customer has following two issues.
Tomcat is: Apache Tomcat/6.0.24, Java is 6 don't know update number
exactly but can find out if necessary.

First...
In catalina*.log log files we get exceptions with following stacktrace
(on a load test we get a lot of them, on normal run we get something
like one/two per hour):

Jun 21, 2010 1:17:21 PM org.apache.catalina.core.ContainerBase
backgroundProcess
WARNING: Exception processing loader WebappLoader[/hidden_name] background process
java.lang.StringIndexOutOfBoundsException: String index out of range: 110
	at java.lang.String.substring(String.java:1934)
	at org.apache.catalina.util.RequestUtil.normalize(RequestUtil.java:131)
	at org.apache.naming.resources.FileDirContext.normalize(FileDirContext.java:771)
	at org.apache.naming.resources.FileDirContext.file(FileDirContext.java:811)
	at org.apache.naming.resources.FileDirContext.getAttributes(FileDirContext.java:429)
	at org.apache.naming.resources.BaseDirContext.getAttributes(BaseDirContext.java:747)
	at org.apache.naming.resources.ProxyDirContext.getAttributes(ProxyDirContext.java:840)
	at org.apache.catalina.loader.WebappClassLoader.modified(WebappClassLoader.java:822)
	at org.apache.catalina.loader.WebappLoader.modified(WebappLoader.java:477)
	at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:398)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:619)


Actual index in "String index out of range: " varies with every occurrence.

What could be causing this? 
Seems to me it is related to web app reloading but this is my blind guess. 
What I know is that app should not be automatically reloaded (nothing 
changes in WEB-INF/* folders) nor is "told" to reload via Tomcat manager.
So please help! :)

Second one...
Don't know if it is related to first one or separate issue. 
>From time to time on a load test we get intermittent 404 errors 
on our jsp pages. "Intermittent" meaning page gives 404 error on a request 
and randomly and next request to a same page goes ok (few miliseconds
later). 
What I know is that:
1. JSP page exists for certain (it is not moved or deleted or anything) 
works ok before it happens, works ok afterwards
2. All JSPs are written in a way that they don't throw any exceptions to 
the outside (surrounded in try/catch everything). If/when code 
invoked inside throws unhandled exception page will produce some custom 
error message inside enclosing catch.

What could be causing this? Is it related to first problem, or a 
completely new one?

Thanks for any info you can provide me,
-- 
Tomy
t.petrovic@inet.hr

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


RE: Classloading

Posted by "Ockleford Paul (NHS Connecting for Health)" <pa...@nhs.net>.
Thanks for the link, useful reading, and thanks for the explanation too.

Paul

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

Nope, it doesn't... Your webapp's classloader delegates to the common
classloader when it can't find something in the webapp - this is the point
of having the common classloader! For example, it allows you to share some
common infrastructure (e.g. DB driver) between several webapps.

So classes in your webapp can depend on common classes, but not the other
way around.

For further reading:
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html, and see
also Java classloaders and chaining in general.

Shay

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

> 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:roji@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)
> <pa...@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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

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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Classloading

Posted by Shay Rojansky <ro...@roji.org>.
Nope, it doesn't... Your webapp's classloader delegates to the common
classloader when it can't find something in the webapp - this is the point
of having the common classloader! For example, it allows you to share some
common infrastructure (e.g. DB driver) between several webapps.

So classes in your webapp can depend on common classes, but not the other
way around.

For further reading:
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html, and see
also Java classloaders and chaining in general.

Shay

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

> 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:roji@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)
> <pa...@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-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: Classloading

Posted by "Ockleford Paul (NHS Connecting for Health)" <pa...@nhs.net>.
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:roji@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)
<pa...@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Classloading

Posted by Shay Rojansky <ro...@roji.org>.
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)
<pa...@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
>
>
> ********************************************************************************************************************
>