You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ed Rouse <er...@milner.com> on 2014/11/11 16:34:06 UTC

custom classloader missing root

I am trying to convert a custom class loader from version 5.5 to version 8.0.11, running under ubuntu.
I have the following line in my context.xml file.
                <Loader loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader" delegate="false" />

I have tried the delegate as both true and false with no difference. I have found that the parent loader is java.net.URLClassLoader, not
org.apache.catalina.loader.WebappLoader or org.apache.catalina.loader.WebappClassLoaderBase as I expected. My class loader extends
org.apache.catalina.loader.WebappClassLoader. In order to add files, as far as I know I need an org.apache.catalina.WebResourceRoot
(probably StandardRoot) and an org.apache.catalina.Context (probably org.apache.catalina.core.StandardContext).

So how do I get, find or create these 2 classes? I think I can create a new StandardRoot if I have a Context, but what needs to be done to create
a proper context for a web application that is getting auto-loaded by the tomcat container at startup?

I am missing some information and have, as yet, not been able to find any details about how to accomplish this.

Thanks.

Re: custom classloader missing root

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

Ed,

On 11/11/14 10:34 AM, Ed Rouse wrote:
> I am trying to convert a custom class loader from version 5.5 to 
> version 8.0.11, running under ubuntu.
> 
> I have the following line in my context.xml file. <Loader
loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader"
delegate="false" />
> 
> I have tried the delegate as both true and false with no
> difference.

I'm a bit late to the party, but I'd like to point out that
delegate="false" will only do something if your own ClassLoader
implements a setDelegate(boolean) method and then actually changes its
own behavior.

> I have found that the parent loader is java.net.URLClassLoader, not
>  org.apache.catalina.loader.WebappLoader or 
> org.apache.catalina.loader.WebappClassLoaderBase as I expected.

You asked Tomcat to use your ClassLoader instead of the standard
WebappClassLoader. Perhaps you meant for your own ClassLoader to
*extend* Tomcat's WebappClassLoader?

> My class loader extends 
> org.apache.catalina.loader.WebappClassLoader.

In that case, you'll get setDelegate as well as everything the
superclass supports. You can get everything WebappClassLoader can do
by calling super.whatever() in IDWMClassLoader.whatever(), or by not
overriding anything from the superclass.

> In order to add files, as far as I know I need an 
> org.apache.catalina.WebResourceRoot (probably StandardRoot) and an 
> org.apache.catalina.Context (probably 
> org.apache.catalina.core.StandardContext).
> 
> So how do I get, find or create these 2 classes? I think I can
> create a new StandardRoot if I have a Context, but what needs to be
> done to create a proper context for a web application that is
> getting auto-loaded by the tomcat container at startup?
> 
> I am missing some information and have, as yet, not been able to
> find any details about how to accomplish this.

Perhaps it would be better if you told us what exactly you are trying
to accomplish by using your own ClassLoader? Is there something that
WebappClassLoader doesn't do for you already?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJUYuEAAAoJEBzwKT+lPKRYA68QAMGhXjSWtW4KU6EjEKqMTPfa
Mn7iiVI7VImyJXg0kiy3QCPS807PsDyVcdDFqm3lsffPivUSYnZ+jcjA2Xpn1Bb1
VNhaQlr9UkPm23cFoQPFwSEhPsy33k9XkI8B0PaRtHsITMZhU23pNSQGbZ16wCuv
aeTxqoUAzToyvlW4Du+5LgjWa4XNj3dBFQoCebICv092D2PSr8cuUTxj5ti7Rhcx
+Qu921VDzlOWQ/j0aXdnn2Eds7g5cZsG7bSTUXJMSyFPRT9HaMbxBOH3k8475aPb
U17A3xhSXRi0kgMjn+Lny8OSiU/Vv5L51IyKmzV2Cn+ymlqRc0G1q1Q0P/itatpQ
rm3a/WYM4XDQt/EYp6BrvQgFb/dDZs9jYBxFvOFQNigh5c60h3yStQlQ9EMLoGqx
9RcvDI+IAqThLqC6aKrpNBAQbGxXOoGgSofX2PqWFC7GZOgqVbUYnE9EG36YzuCQ
dc3vPBBbasPvNwHID1NJbDNGmR8rc7ilM4s050sH/5WNlVOyHehA3j3jStrXdDkp
F/B04wjKsYS/IoNb/xrPdUHzdrVj9jZudDDbiNTeiU5Jk3tkVEBnBUWJa2KaJ2cj
pOV0NZBkbOHbMPNY8VRmcErg45Czy+UARK/CpVOzDtp8JEFbsMbUSBgiVtq7uUcv
5m8PxVl5f84IW6KtOeAz
=7Rdm
-----END PGP SIGNATURE-----

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


Re: custom classloader missing root

Posted by Mark Thomas <ma...@apache.org>.
On 11/11/2014 17:20, Ed Rouse wrote:
>> -----Original Message-----
>> From: Mark Thomas [mailto:markt@apache.org]
>> Sent: Tuesday, November 11, 2014 12:14 PM
>> To: Tomcat Users List
>> Subject: Re: custom classloader missing root
>>
>> On 11/11/2014 17:01, Ed Rouse wrote:

<snip/>

>>> I already tried getResources() but it returns null. hence my
>>> confusion. As far as I can tell, tomcat is not setting the root or
>>> context on my class loader.
>>
>> That depends on when you call it.
> 
> Since it is the <Loader> in the context.xml file, I am not calling it, tomcat is.

You said you tried getResources() but it returns null.

Again, the result from getResources() in this case depends on when you
call it.

> Is there another way to do this so I can call it manually from within the webapp?

Nope.

Mark

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


RE: custom classloader missing root

Posted by Ed Rouse <er...@milner.com>.

> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Tuesday, November 11, 2014 12:14 PM
> To: Tomcat Users List
> Subject: Re: custom classloader missing root
> 
> On 11/11/2014 17:01, Ed Rouse wrote:
> >
> >
> > -----Original Message----- From: Mark Thomas
> [mailto:markt@apache.org]
> > Sent: Tuesday, November 11, 2014 11:49 AM
> > To: Tomcat Users List Subject: Re: custom classloader missing root
> >
> > On 11/11/2014 15:34, Ed Rouse wrote:
> >> I am trying to convert a custom class loader from version 5.5 to
> >> version 8.0.11, running under ubuntu. I have the following line in
> my
> >> context.xml file. <Loader
> >> loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader"
> >> delegate="false" />
> >>
> >> I have tried the delegate as both true and false with no difference.
> >> I have found that the parent loader is java.net.URLClassLoader, not
> >> org.apache.catalina.loader.WebappLoader or
> >> org.apache.catalina.loader.WebappClassLoaderBase as I expected.
> >
> > Your expectation is incorrect.
> >
> >> My class loader extends
> >> org.apache.catalina.loader.WebappClassLoader. In order to add files,
> >> as far as I know I need an org.apache.catalina.WebResourceRoot
> >> (probably StandardRoot) and an org.apache.catalina.Context (probably
> >> org.apache.catalina.core.StandardContext).
> >>
> >> So how do I get, find or create these 2 classes?
> >
> > You don't create them. You don't have access to the Context. Tomcat
> > creates them and sets them on your class loader. You then access them
> > with getResources() and getResources().getContext().
> >
> >> I think I can create a new StandardRoot if I have a Context, but
> what
> >> needs to be done to create a proper context for a web application
> >> that is getting auto-loaded by the tomcat container at startup?
> >
> > Tomcat does all of this for you.
> >
> >> I am missing some information and have, as yet, not been able to
> find
> >> any details about how to accomplish this.
> >
> > The source code is usually a good place to start. If you can't figure
> > out how stuff works from the source fire up a Tomcat instance, attach
> > a debugger and step through the code.
> >
> > Mark
> >
> > I already tried getResources() but it returns null. hence my
> > confusion. As far as I can tell, tomcat is not setting the root or
> > context on my class loader.
> 
> That depends on when you call it.

Since it is the <Loader> in the context.xml file, I am not calling it, tomcat is. 
Is there another way to do this so I can call it manually from within the webapp?

> 
> >
> > As for looking through the source, I'm not even sure where to start.
> 
> How about the source for WebappClassLoader and look for where
> setResources() is called?
> 
> > Is there a document somewhere that goes through the entire startup
> > process of the tomcat container so I will at least have an idea of
> > where the tomcat is supposed to be doing this?
> 
> Nothing current but it hasn't changed much since this was written:
> http://cp.mcafee.com/d/k-Kr6xASyMy-
> ejsK_sTsSztcQsLL6zAsepdETjd7bXNEVujpdETjd7bXNEV73C3qdQPhO-
> qekknD3vNGTjMkH8-7NVsSH8-7NVsSzXb2rz3_nV-
> UVB_HTbFILnUQsLfTd7fbnhIyyHt57BgY-
> F6lK1FJ4SyrKrKr01DRJFVeJ9UxmRcSdysF_qrsvOAZzdJrwsrrFYq5U_dKc2WrZTQTy_NG
> TjPBp7M-fbwGtlrrfJmSNf-
> 00CS7DTzobZ8QgmrFeGFEwIvJa7RR3UCy1mlaiwhd44qRCrpvdBSUG
> 
> Mark
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org


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


Re: custom classloader missing root

Posted by Mark Thomas <ma...@apache.org>.
On 11/11/2014 17:01, Ed Rouse wrote:
> 
> 
> -----Original Message----- From: Mark Thomas
> [mailto:markt@apache.org] Sent: Tuesday, November 11, 2014 11:49 AM 
> To: Tomcat Users List Subject: Re: custom classloader missing root
> 
> On 11/11/2014 15:34, Ed Rouse wrote:
>> I am trying to convert a custom class loader from version 5.5 to
>> version 8.0.11, running under ubuntu. I have the following line in
>> my context.xml file. <Loader 
>> loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader" 
>> delegate="false" />
>> 
>> I have tried the delegate as both true and false with no
>> difference. I have found that the parent loader is
>> java.net.URLClassLoader, not
>> org.apache.catalina.loader.WebappLoader or
>> org.apache.catalina.loader.WebappClassLoaderBase as I expected.
> 
> Your expectation is incorrect.
> 
>> My class loader extends
>> org.apache.catalina.loader.WebappClassLoader. In order to add
>> files, as far as I know I need an 
>> org.apache.catalina.WebResourceRoot (probably StandardRoot) and an
>> org.apache.catalina.Context (probably
>> org.apache.catalina.core.StandardContext).
>> 
>> So how do I get, find or create these 2 classes?
> 
> You don't create them. You don't have access to the Context. Tomcat
> creates them and sets them on your class loader. You then access them
> with getResources() and getResources().getContext().
> 
>> I think I can create a new StandardRoot if I have a Context, but
>> what needs to be done to create a proper context for a web
>> application that is getting auto-loaded by the tomcat container at
>> startup?
> 
> Tomcat does all of this for you.
> 
>> I am missing some information and have, as yet, not been able to
>> find any details about how to accomplish this.
> 
> The source code is usually a good place to start. If you can't figure
> out how stuff works from the source fire up a Tomcat instance, attach
> a debugger and step through the code.
> 
> Mark
> 
> I already tried getResources() but it returns null. hence my
> confusion. As far as I can tell, tomcat is not setting the root or
> context on my class loader.

That depends on when you call it.

> 
> As for looking through the source, I'm not even sure where to start.

How about the source for WebappClassLoader and look for where
setResources() is called?

> Is there a document somewhere that goes through the entire startup
> process of the tomcat container so I will at least have an idea of
> where the tomcat is supposed to be doing this?

Nothing current but it hasn't changed much since this was written:
http://localhost/docs/architecture/startup.html

Mark

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


RE: custom classloader missing root

Posted by Ed Rouse <er...@milner.com>.

-----Original Message-----
From: Mark Thomas [mailto:markt@apache.org] 
Sent: Tuesday, November 11, 2014 11:49 AM
To: Tomcat Users List
Subject: Re: custom classloader missing root

On 11/11/2014 15:34, Ed Rouse wrote:
> I am trying to convert a custom class loader from version 5.5 to version 8.0.11, running under ubuntu.
> I have the following line in my context.xml file.
>                 <Loader 
> loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader" 
> delegate="false" />
> 
> I have tried the delegate as both true and false with no difference. I 
> have found that the parent loader is java.net.URLClassLoader, not org.apache.catalina.loader.WebappLoader or org.apache.catalina.loader.WebappClassLoaderBase as I expected.

Your expectation is incorrect.

> My class loader extends org.apache.catalina.loader.WebappClassLoader. 
> In order to add files, as far as I know I need an 
> org.apache.catalina.WebResourceRoot
> (probably StandardRoot) and an org.apache.catalina.Context (probably org.apache.catalina.core.StandardContext).
>
> So how do I get, find or create these 2 classes? 

You don't create them. You don't have access to the Context. Tomcat creates them and sets them on your class loader. You then access them with getResources() and getResources().getContext().

> I think I can create a new StandardRoot if I have a Context, but what 
> needs to be done to create a proper context for a web application that is getting auto-loaded by the tomcat container at startup?

Tomcat does all of this for you.

> I am missing some information and have, as yet, not been able to find any details about how to accomplish this.

The source code is usually a good place to start. If you can't figure out how stuff works from the source fire up a Tomcat instance, attach a debugger and step through the code.

Mark

I already tried getResources() but it returns null. hence my confusion. As far as I can tell, tomcat is not setting the root or context on my class loader.

As for looking through the source, I'm not even sure where to start. Is there a document somewhere that goes through the entire startup process of the tomcat container so I will at least have an idea of where the tomcat is supposed to be doing this?

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


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


Re: custom classloader missing root

Posted by Mark Thomas <ma...@apache.org>.
On 11/11/2014 15:34, Ed Rouse wrote:
> I am trying to convert a custom class loader from version 5.5 to version 8.0.11, running under ubuntu.
> I have the following line in my context.xml file.
>                 <Loader loaderClass="com.comsquared.idw.catalina.ext.IDWMClassLoader" delegate="false" />
> 
> I have tried the delegate as both true and false with no difference. I have found that the parent loader is java.net.URLClassLoader, not
> org.apache.catalina.loader.WebappLoader or org.apache.catalina.loader.WebappClassLoaderBase as I expected.

Your expectation is incorrect.

> My class loader extends org.apache.catalina.loader.WebappClassLoader. In order to add files, as far as I know I need an org.apache.catalina.WebResourceRoot
> (probably StandardRoot) and an org.apache.catalina.Context (probably org.apache.catalina.core.StandardContext).
>
> So how do I get, find or create these 2 classes? 

You don't create them. You don't have access to the Context. Tomcat
creates them and sets them on your class loader. You then access them
with getResources() and getResources().getContext().

> I think I can create a new StandardRoot if I have a Context, but what needs to be done to create
> a proper context for a web application that is getting auto-loaded by the tomcat container at startup?

Tomcat does all of this for you.

> I am missing some information and have, as yet, not been able to find any details about how to accomplish this.

The source code is usually a good place to start. If you can't figure
out how stuff works from the source fire up a Tomcat instance, attach a
debugger and step through the code.

Mark


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