Elgs,

On 9/25/12 1:15 PM, Elgs Chen wrote:
> 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!

Note that Tomcat separates ClassLoaders in this way to protect
"system"-level classes from being loaded by web applications. By
changing the parent ClassLoader, you are undoing that protection.

-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to