Summary: | NoClassDefFoundError using ServletContextListener WITH CUSTOM LOADER | ||
---|---|---|---|
Product: | Tomcat 5 | Reporter: | Christian Elsen <ehcapa.allizgub> |
Component: | Unknown | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | leroux_bruno, mabuffo |
Priority: | P3 | ||
Version: | 5.5.15 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows XP |
Description
Christian Elsen
2005-10-12 18:46:35 UTC
Works for me on 5.5.12 right out of the box. I'm attaching a WAR you can use to test if you'd like, and closing this issue. Please attach the war, I'll try it against my installation and check why it doesn't work. I'm re-opening this as I have a project that worked fine in 5.5.9 and doesn't work in 5.5.12 (similar to the original poster). I tracked the issue down to my server.xml (see below). I was using a <Loader> element under <Host> element. Even with an empty <Loader/> element I get the NoClassDefFoundError. When I take out the element completely it works. My stack trace is: SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener My server.xml is: <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.core.AprLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener" /> <Service name="Catalina"> <Connector port="8080" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" /> <Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> <Engine name="Catalina" defaultHost="localhost"> <Host name="localhost" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="" docBase="d:\jproj-3.1\iod- guide\src\main\webapp"> <Loader/> </Context> </Host> </Engine> </Service> </Server> This is causing trouble for me as I want to use a custom classloader derived from WebappClassLoader. Is there any workaround? Thanks, Alfie. I also have a project that worked under 5.5.9, but under 5.5.15, I get this on startup: 2006-01-12 19:00:02,351 [ERROR] main org.apache.catalina.core.ContainerBase.[Catalina].[bolweb].[/] - Error configuring application listener of class org.apache.myfaces.webapp.StartupServletContextListener java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener I am also using a loader tag in server.xml. If i remove it, it works fine...but I need it. It is the responability of your custom Loader to correctly resolve the parent ClassLoader (by calling getParentClassLoader on the Container). It's possible that the Tomcat developers could make this easier for people extending WebappLoader (which is why I'm not actually closing the bug), but in the meantime, something like: public void start() throws LifecycleException { Thread cthrd = Thread.currentThread(); ClassLoader oldcl = cthrd.getContextClassLoader(); cthrd.setContextClassLoader(getContainer().getParentClassLoader()); super.start(); cthrd.setContextClassLoader(oldcl); } should do as a work-around. Thank you. I also just found that it works if i add delegate="true" to the loader tag. Adding delegate="true" doesn't work for me. Even if I just have: <Loader delegate="true"/> It doesn't work. NoClassDefFoundError: javax/servlet/ServletContextListener. Also, can you confirm the sample code should go in WebappLoader and not WebappClassLoader. I'm overriding the latter and don't need to override WebappLoader (unless I need to to get this working!). Thanks, Alfie. (In reply to comment #6) > Thank you. I also just found that it works if i add delegate="true" to the > loader tag. I was mistaken. This actually did not work. I also tried william's workaround (getParentClassLoader), and it didn't help. Changing summary text of this issue to indicate the key fact that you're using a custom loader, and updating version to 5.5.15 per comment above. *** Bug 37302 has been marked as a duplicate of this bug. *** *** Bug 38877 has been marked as a duplicate of this bug. *** - Using the setParentCL rule is not nice at all, as it (dumbly) overrides any possible configuration which could be done when embedding. - From what the related reports wrote, this does not affect context files (only when the Context element is in server.xml). You should be using that -> So overall, this bug should not get fixed (I will not bother closing it, as I am sure it would be reopened right away, though). *** This bug has been marked as a duplicate of 39704 *** |