You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alberto Romei <a....@centrosistemi.it> on 2003/04/11 13:23:15 UTC
Custom ClassLoader
Hi, all !
I need to tell tomcat to use a custom implementation of ClassLoader for a
specific context.
The documentation explains the use of <Loader loaderClass="pkg.ClassName">
inside the <Context> element, but I saw that the "loaderClass" attribute is
ignored (bug #12501).
The only way I found is to create a subclass of WebappLoader and specify it
in <Loader className="prova.MyLoader">, tweaking the getClassLoader()
method.
Here is the code of my experiment :
= = = = = = = = = =
package prova;
import java.io.*;
import java.net.*;
import org.apache.catalina.loader.WebappLoader;
import org.apache.catalina.loader.WebappClassLoader;
public class MyLoader extends WebappLoader
{
static
{
System.out.println("*****************Here I am*******************");
}
ClassLoader cl;
public MyLoader()
{
super();
}
public MyLoader(java.lang.ClassLoader parent)
{
super(parent);
}
public ClassLoader getClassLoader()
{
if (cl==null)
{
URLClassLoader push = (URLClassLoader)super.getClassLoader();
cl = new URLClassLoader(push.getURLs(), push)
{
public String toString()
{
String rv = "***** Prova *****\r\n";
URL arr[] = ((WebappClassLoader)this.getParent()).getURLs();
for (int i=0; i<arr.length; i++)
rv += arr[i]+"\r\n";
rv += "***** Prova *****\r\n";
rv += super.toString();
return rv;
}
};
}
return cl;
}
}
= = = = = = = = = =
I placed the class under tomcat/common/classes and it is loaded normally (i
see "*****************Here I am*******************" in the output), but
tomcat cannot compile JSPs any more. When I make a request to a jsp, I get
errors like:
Class javax.servlet.http.HttpServlet not found...
Package javax.servlet not found in import...
It seems like the classloader has lost all the paths, even if I set the
parent of my ClassLoader to the default WebappClassLoader.
Any suggestion is appreciated...
Thanks
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org