tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elgs Chen <elgs1...@hotmail.com>
Subject Re: WebClassLoader using SystemClassLoader to load ServletDef?
Date Tue, 25 Sep 2012 17:15:15 GMT
Hi Mark,

I finally get my homework done. Thank you so much for pointing me to the right direction.
That really helped me to gain huge insight into the inner world of the tomcat.

I used JPDA to attach my eclipse to tomcat. Then I was able to see everything happens with
the WebappClassLoader.loadClass. For my question, the key is to set the WebappClassLoader's
parent class loader. Previously it was the system class loader, which is not intended. As
this became obvious, I added a line to set the server's parent class loader, like this:

final StandardServer server = (StandardServer) tomcat.getServer();
server.setParentClassLoader(TomcatMain.class.getClassLoader());

Now the server's parent class loader becomes my URLClassLoader, and that is the class loader
being able to load all the jars I put in the lib directory. Then I start my Bootstrap, it
works like a charm!!

Mark, thank you so much. I really really appreciate you fast and kind help!

Best regards,
Elgs

On Sep 25, 2012, at 11:04 PM, Elgs Chen <elgs1980@hotmail.com> wrote:

> Hi Mark,
> 
> Thanks for your fast answer. That helped me to narrow down the scope of this problem.
I understand line 262 is to initialize and create the common, shared and catalina class loaders.
But I'm still struggling how the WebappClassLoader.loadClass(String name, boolean resolve)
be able to load the class ServletDef. Can you please give me some more insight into this method?
I think the it should load the class via the catalina class loader as my previous assumption
1 was wrong. If this is the case, How does this method achieve that?
> 
> Many thanks,
> Elgs
> 
> 
> On Sep 25, 2012, at 9:28 PM, Mark Thomas <markt@apache.org> wrote:
> 
>> On 25/09/2012 13:19, Elgs Chen wrote:
>>> Dear Tomcat Developers,
>>> 
>>> I have a question regarding the behavior of the WebClassLoader.loadClass(String
name, boolean resolve) in the org.apache.catalina.loader package.
>>> 
>>> I have the following assumptions, please correct me if any is wrong:
>>> 1, It seems the WebClassLoader only uses the SystemClassLoader (or AppClassLoader)
to loader tomcat core classes, like ServletDef;
>> 
>> Wrong. See [1].
>> 
>>> 2, It seems if tomcat is started up by the startup.sh from the bin directory,
the classpath in the startup command line will include only the jars in the bin directory:
bootstrap.jar, commons-daemon.jar and tomcat-juli.jar;
>> 
>> Correct.
>> 
>>> 3, ClassLoader.getSystemClassLoader() by default returns the class loader with
the startup command-line classpath; 
>> 
>> Correct.
>> 
>>> Now if the above three assumption are correct, it seems that it's not possible
for the WebClassLoader to load the tomcat core classes as only the few bootstrap jars are
in the system class loader's classpath. However, the fact is the startup.sh script indeed
starts tomcat up. Why?
>> 
>> The logical conclusion would be that one or more of the assumptions is
>> wrong.
>> 
>> 
>>> So my question is:
>>> How does the startup.sh shipped with tomcat binary make the WebClassLoader to
load the ServletDef?
>> 
>> See [2], line 262.
>> 
>> Mark
>> 
>> 
>> [1] http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
>> [2]
>> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Bootstrap.java?view=annotate
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: dev-help@tomcat.apache.org
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
> 
> 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message