You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Niclas Hedhman <ni...@localbar.com> on 2000/03/27 10:46:05 UTC

Classloading in Cocoon 2

Pier,
You have a comment
        // This is better than Class.forName() because components should
be
        // loaded by the same classloader that loaded Cocoon (they
should
        // be in the same jar file, or directory.
regarding

return(this.getClass().getClassLoader().loadClass(className));

And afaik, this is a direct subsitution for Class.forName() in JVM 1.2.
The same delegation model will occur, it wouldn't surprise me if
Class.forName() does the above, but needs to fondle with the stack to
get the class of the calling object.

Your statement "they should be in the same jar..." is also incorrect,
since we can expect many add-ons to Cocoon in the future that will be in
their own Jars/directories.

I would recommend to use the Context Classloader instead, which is the
Classloader used for the executing thread, and typically is the initial
classloader.

            return
Thread.currentThread().getContextClassLoader().loadClass(className);

Note; This is a 1.2 feature...

Niclas


Re: Classloading in Cocoon 2

Posted by Pierpaolo Fumagalli <pi...@apache.org>.
Niclas Hedhman wrote:
> 
> Thread.currentThread().getContextClassLoader().loadClass(className);
> Note; This is a 1.2 feature...

So... Now either JDK 1.2 or 1.1... Let's choose once for all...

	Pier

-- 
----------------------------------------------------------------------
pier: stable structure erected over water to allow docking of seacraft
<ma...@betaversion.org>      <http://www.betaversion.org/~pier/>
----------------------------------------------------------------------