You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Stefano Mazzocchi <st...@apache.org> on 2001/02/21 22:48:28 UTC

classloader suggestion

here is a suggestion that Craig sent me privately.... can you guys take
care of this? thanks.

                             - o -

However, here's an algorithm that will work on any servlet container
that uses
URLClassLoader (as Tomcat 4.0 does):

* Get the classloader for the webapp:
    ClassLoader cl = this.getClass().getClassLoader()

* Cast it to URLClassLoader and call getURLs().

* Extract the paths from these URLs and add them to the classpath
  you are constructing.

* Call getParent() to get this class loader's parent classloader.

* If the parent classloader is also a URLClassLoader, repeat the
  previous three steps.

By the time this loop terminates, you will have all the JAR files and
directories
that are visible to the web app, no matter how many class loaders are
involved and
no matter which class loader contains which particular JAR files.

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<st...@apache.org>                             Friedrich Nietzsche
--------------------------------------------------------------------


Re: classloader suggestion

Posted by Berin Loritsch <bl...@apache.org>.
Stefano Mazzocchi wrote:
> 
> here is a suggestion that Craig sent me privately.... can you guys take
> care of this? thanks.
> 
>                              - o -
> 
> However, here's an algorithm that will work on any servlet container
> that uses
> URLClassLoader (as Tomcat 4.0 does):
> 
> * Get the classloader for the webapp:
>     ClassLoader cl = this.getClass().getClassLoader()
> 
> * Cast it to URLClassLoader and call getURLs().
> 
> * Extract the paths from these URLs and add them to the classpath
>   you are constructing.
> 
> * Call getParent() to get this class loader's parent classloader.
> 
> * If the parent classloader is also a URLClassLoader, repeat the
>   previous three steps.
> 
> By the time this loop terminates, you will have all the JAR files and
> directories
> that are visible to the web app, no matter how many class loaders are
> involved and
> no matter which class loader contains which particular JAR files.

Ok--sounds cool, but how about all the ServletContainers that don't
use URLClassLoaders?  You know, like IBM.