Hi All!

Briefly: it seems to me that the standard implementation of Loader loads class 
of web application class loader in a too contrained way. Here follow the 
details. 
I have a task to extend the standard implementation of web app class loader in 
a certain way. The main condition is that my class loader implementation 
(MyWebappClassLoader) must reside among my application's classes, because it 
references many of them. The standard implementation of Loader (WebappLoader) 
which is responsible for loading of web app class loader's class, contains the 
following lines of code (Tomcat 6.0.18 source code):

      // WebappLoader.java:
    private WebappClassLoader createClassLoader()
        throws Exception {

        Class clazz = Class.forName(loaderClass);
        .............

My extension of WebappLoader (MyWebappLoader) also resides in my application's 
classes. I can load it successfully with the help of another WebappClassLoader 
in some tricky way. With the above mentioned approach, I was expecting that 
MyWebappClassLoader will be successfully loaded as well, however it is not (I 
get ClassNotFoundException from Class.forName() call).
Finally I figured out that Class.forName() uses for loading the defining class 
loader of the _current_ class, and the current class for that code is 
superclass WebappLoader but not MyWebappLoader itself. WebappLoader is loaded 
by StandardClassLoader, but not by the application-aware class loader 
WebappClassLoader which loads MyWebappLoader. So MyWebappClassLoader of course 
cannot be found by StandardClassLoader. I believe that a single correction like 
this would make me happy:

Class clazz = Class.forName(loaderClass, true, 
this.getClass().getClassLoader());

because this.getClass().getClassLoader() would produce class loader used to 
load MyWebappLoader (i.e. that would be an instance of WebappClassLoader, but 
not StandardClassLoader). 
So, is not it an unnecessary limitation to WebappLoader? And is this something 
that could be fixed in future? I will appreciate any comments on that!

Regards,
Pavel



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to