You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Afkham Azeez <af...@gmail.com> on 2011/04/13 16:05:05 UTC

Child-first classloading with Embedded Tomcat 7.0.11

Hi,
We are using Embedded Tomcat 7.0.11. It seems that with Embedded Tomcat, the
default is parent-first class loading, even though the default in the Tomcat
binary distribution is child-first. Is there a way to setup child-first
class loading in Embedded Tomcat?

Thanks
Azeez

Re: Child-first classloading with Embedded Tomcat 7.0.11

Posted by Afkham Azeez <af...@gmail.com>.
Was able to solve this using a bootstrap mechanism.
http://frank.zinepal.com/embedded-tomcat-class-loading-trickery was helpful.

Azeez

On Wed, Apr 13, 2011 at 8:33 PM, Afkham Azeez <af...@gmail.com> wrote:

> According to http://yzb.hit.edu.cn/docs/class-loader-howto.html,
> everything in the system classpath will be visible to webapps, and hence
> will override the classes in the webapps, I think. So, the solution would be
> to implement a bootstrap mechanism, just
> like org.apache.catalina.startup.Bootstrap, is it?
>
>

Re: Child-first classloading with Embedded Tomcat 7.0.11

Posted by Afkham Azeez <af...@gmail.com>.
According to http://yzb.hit.edu.cn/docs/class-loader-howto.html, everything
in the system classpath will be visible to webapps, and hence will override
the classes in the webapps, I think. So, the solution would be to implement
a bootstrap mechanism, just like org.apache.catalina.startup.Bootstrap, is
it?

On Wed, Apr 13, 2011 at 7:35 PM, Afkham Azeez <af...@gmail.com> wrote:

> Hi,
> We are using Embedded Tomcat 7.0.11. It seems that with Embedded Tomcat,
> the default is parent-first class loading, even though the default in the
> Tomcat binary distribution is child-first. Is there a way to setup
> child-first class loading in Embedded Tomcat?
>
> Thanks
> Azeez
>



-- 
*Afkham Azeez*
Senior Software Architect & Senior Manager; WSO2, Inc.; http://wso2.com,
*
*
*Member; Apache Software Foundation;
**http://www.apache.org/*<http://www.apache.org/>
*
email: **azeez@wso2.com* <az...@wso2.com>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
*
*

Re: Child-first classloading with Embedded Tomcat 7.0.11

Posted by Afkham Azeez <af...@gmail.com>.
On Thu, Apr 14, 2011 at 3:41 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Afkham,
>
> On 4/13/2011 10:05 AM, Afkham Azeez wrote:
> > We are using Embedded Tomcat 7.0.11. It seems that with Embedded Tomcat,
> the
> > default is parent-first class loading, even though the default in the
> Tomcat
> > binary distribution is child-first.
>
> Yes. If you are hosting a Tomcat container, it is your job to make sure
> that the system classpath is sane.
>
> > Is there a way to setup child-first class loading in Embedded Tomcat?
>
> Tomcat will always follow the servlet standard by searching the system
> classloader first, then the webapp classloader, then the parent of the
> webapp classloader.
>
> http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
>
> Search for the word "therefore" and you'll see it laid-out in plain
> English.
>
>
Thanks Chris. Yes, our mistake was to put everything into the system
classloader (classpath). We have solved it with a bootstrap mechanism
similar to the one used in standard Tomcat. Thanks.


> It appears from your reference (in a followup post to your own) that you
> can set the context classpath of the thread that launches Tomcat and
> effectively change the "system" classpath as Tomcat sees it.
>
> Be careful with these things and always make sure you test everything:
> ClassLoading issues can cause unexpected behavior.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk2mH6QACgkQ9CaO5/Lv0PCiRACgv0pOl0xFGPuLOQdDBRkqjHxS
> Tu4AnRHS/aAs0F5jdtNIV86TT2hX7xai
> =PN5V
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
*Afkham Azeez*
Senior Software Architect & Senior Manager; WSO2, Inc.; http://wso2.com,
*
*
*Member; Apache Software Foundation;
**http://www.apache.org/*<http://www.apache.org/>
*
email: **azeez@wso2.com* <az...@wso2.com>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
*
*

Re: Child-first classloading with Embedded Tomcat 7.0.11

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Afkham,

On 4/13/2011 10:05 AM, Afkham Azeez wrote:
> We are using Embedded Tomcat 7.0.11. It seems that with Embedded Tomcat, the
> default is parent-first class loading, even though the default in the Tomcat
> binary distribution is child-first.

Yes. If you are hosting a Tomcat container, it is your job to make sure
that the system classpath is sane.

> Is there a way to setup child-first class loading in Embedded Tomcat?

Tomcat will always follow the servlet standard by searching the system
classloader first, then the webapp classloader, then the parent of the
webapp classloader.

http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html

Search for the word "therefore" and you'll see it laid-out in plain English.

It appears from your reference (in a followup post to your own) that you
can set the context classpath of the thread that launches Tomcat and
effectively change the "system" classpath as Tomcat sees it.

Be careful with these things and always make sure you test everything:
ClassLoading issues can cause unexpected behavior.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2mH6QACgkQ9CaO5/Lv0PCiRACgv0pOl0xFGPuLOQdDBRkqjHxS
Tu4AnRHS/aAs0F5jdtNIV86TT2hX7xai
=PN5V
-----END PGP SIGNATURE-----

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