I'm trying to embed tomcat 4.1.30 into another application and keep
running into annoying classloader problems.  Unfortunately, I can't
assume that I have control over the host application's classpath.  :( 
Here's what I've created:

TomcatStarter.class:  This class contains a setup() method that creates
the tomcat Embedded object and sets up the host, context, and such. 
Obviously it has direct references to classes in the tomcat jars.

TomcatWrapper.class:  This class extends Thread and contains a main()
method for instantiating and running the thread.  The constructor sets
the thread's contextClassLoader to be a URLClassLoader containing all of
the Tomcat jar files.  The run() method uses
getContextClassLoader().loadClass("TomcatStarter") to create the tomcat
starter.  This decouples the Wrapper from the Starter so that the
wrapper does not need to load any tomcat jars in order to run tomcat.

If I run TomcatWrapper.main() and set the classpath on the command line
to contain all of the Tomcat server/lib and common/lib jars, then it
runs fine.  I can access the configured contexts.  This is good, but not
quite what I need since I don't want to change the startup classpath.

If I run TomcatWrapper.main() and leave off the tomcat jars from the
classpath, then I can create the embedded tomcat, but I get an error
when it runs (see exception trace below).  The exception appears to
indicate that the WebappClassLoader can't find jasper-compiler.jar in
common/lib, even though it is available through the thread's
contextClassLoader (I tested this by running
loadClass("org.apache.jasper.servlet.JspServlet") on the
contextClassLoader).

Is it not possible to set tomcat's classpath using a thread's
contextClassLoader()?  Am I required to change the classpath of hte host
application to run an embedded tomcat?

--Wart


javax.servlet.ServletException: Wrapper cannot find servlet class
org.apache.jasper.servlet.JspServlet or a class it depends on
        at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:891)
        at
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
        at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3427)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:3628)
        at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)        at 
org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
        at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)        at 
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363)
        at org.apache.catalina.startup.Embedded.start(Embedded.java:994)
        at
edu.caltech.hep.wart.ml.TomcatStarter.run(TomcatStarter.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
edu.caltech.hep.wart.ml.TomcatWrapper.run(TomcatWrapper.java:131)
----- Root Cause -----
java.lang.ClassNotFoundException: org.apache.jasper.servlet.JspServlet
        at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1443)
        at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1289)
        at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:885)
        at
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
        at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3427)
        at
org.apache.catalina.core.StandardContext.start(StandardContext.java:3628)
        at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)        at 
org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
        at
org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)        at 
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363)
        at org.apache.catalina.startup.Embedded.start(Embedded.java:994)
        at
edu.caltech.hep.wart.ml.TomcatStarter.run(TomcatStarter.java:71)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
edu.caltech.hep.wart.ml.TomcatWrapper.run(TomcatWrapper.java:131)





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

Reply via email to