I don't fully understand your setup from the messages you sent but if you
have a custom class loader then you should register webapp class loader to
be the parent of your custom class loader. So, if your custom class loader
lives in webapp directory its constructor should look like:

public class CustomClassLoader
{
   public CustomClassLoader()
   {
        super(this.getClass().getClassLoader()  //1
   }
}

and then load your classes like

CustomClassLoader ccl = new CustomClassLoader();
Class clazz = Class.forName("xyz.zyx.Foo", true, ccl);

if you skip lilne 1 or have just call to super() then there's simply no way
you can load classes from webapp directory through this classloader, unless
it's implemented that way (btw it's a bad idea) , because system class
loader is set as the parent of ccl, and sys class loader has no clue of how
to load classes from webapp directory.
So, if you write your class loader the above way ccl will first try to
delegate class loading up the class loader tree, which will fail, so it'll
try to load the class itself. As the result of loading class xyz.zyx.Foo any
intefaces loading it implements will be unitiated through ccl, which will be
delegated to webapp class loader, so there should be no problem finding them
in jar files located in webapp directory. There's also a possibility you can
get nasty ClassCast exceptions because of the fact JVM considers  a class to
be a combination of class and its class loader, so the same byte array
represineting a class loaded through different class loaders is not the same
class to the JVM.

--V.


----- Original Message -----
From: "jochen mader" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, August 13, 2001 6:16 AM
Subject: Re: ClassLoader


>
> > Moving things from Tomcat's internal classes (any version) into your
> > /WEB-INF/lib is *not* going to work.
> >
> > What are you trying to accomplish that the standard class loading model
> > does not support?  Just saying "I want to use a classloader inside my
> > servlet" does not help much in getting useful suggestions.
> >
> > > Thanks in advance
> > > Jochen
> >
> > Craig McClanahan
>
> I'm trying to allow my servlet to download classes from another server via
> RMI and to use those classes. The problem now is that when I downloaded
the
> classes and I try to define the class via the ClassLoader the ClassLoader
> tells me that it can't find the required interface classes (which are
stored
> in the jars inside the WEB-INF/lib directory). By looking through your
> archive I found the following post:
>
> http://w6.metronet.com/~wjm/tomcat/2001/Feb/msg00096.html
>
> *snip*
>
> >
> > Am I just screwed or is there some cool trick that I am missing?  Of
course
> > I could change the deployment scheme to put a copy of the dispatcher
> > servlet into each apps WE-INF/classes, but this seems a bit clunky.
> >
>
> It's not clunky -- its required by virtue of the fact that classloaders
know
> how to delegate upwards but not downwards.  For lots of security related
> reasons, that is actually a Good Thing.
>
> *snip*
>
> Is this post wrong and is there another sollution?
> And if not: which of all those classes is the "dispatcher servlet"?
>
> Thx
> Jochen
>
>

Reply via email to