tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joel P. Worrall" <jworr...@commnav.com>
Subject XML ClassCastException and tomcat 4.0 documentation
Date Wed, 24 Oct 2001 21:04:10 GMT
I am facing a terrible dilemma and in need of accurate information.

I believe my issue deals with the Tomcat 4 class loaders and my problem
surrounds the use of Tomcat 4.0.1 on jdk 1.4 with the JDOM beta 7 jar.

2 scenarios:

1.  unpack tomcat 4, configure the server.xml to look to my webapp.

My application WEB-INF/lib jar contains jdom beta 7 and the latest and
greatest xerces jar (built from source of xml.apache.org).  (Note that we
now have a xerces jar in the CATALINA_HOME/common/lib directory AND my
webapp/WEB-INF/lib directories)

For some reason, despite the fact that both xerces are recent, the following
exception occurs.

javax.servlet.ServletException: Servlet.init() for servlet jsp threw
exception
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:871)
	at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:
3267)
	at org.apache.catalina.core.StandardContext.start
....
----- Root Cause -----
java.lang.ClassCastException:
org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
	at
javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.
java:103)
	at
org.apache.jasper.parser.ParserUtils.parseXMLDocument(ParserUtils.java:183)
	at
org.apache.jasper.compiler.TldLocationsCache.processWebDotXml(TldLocationsCa
che.java:165)
	at
org.apache.jasper.compiler.TldLocationsCache.<init>(TldLocationsCache.java:1
38)
	at
org.apache.jasper.EmbededServletOptions.<init>(EmbededServletOptions.java:32
4)
	at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:266)
	at org.apache.catalina.core.StandardWrapper.load
......

For some reason, the ClassLoader(?) get confused and spits back a that
ClassCastException, claiming that the xerces DocumentBuilderFactory
implementation does not implement the interface - when it clearly does.

2.  Ok, so I remove the xerces.jar from the webapp/WEB-INF/lib directory.

I startup the system.  Now the jspservlet starts fine but my own servlet
that (a few levels deeper) makes a call to org.jdom.input.SAXBuilder chokes
b/c the org.apache.xerces.parsers.SAXParser is being cast to an XMLReader.
Now I checked the xerces.jar's SAXParser class AND IT DOES implement
XMLReader, but it throws the following exception none the less.

This leads me to believe its ClassLoader issue.

javax.servlet.ServletException: Error in building:
org.apache.xerces.parsers.SAXParser
	at com.commnav.sbh.servlets.ControlServlet.init(ControlServlet.java:155)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:852)
.....
org.jdom.JDOMException: Error in building:
org.apache.xerces.parsers.SAXParser
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:306)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:583)
	at
com.commnav.sbh.framework.config.ServletConfigConfiguration.<init>(ServletCo
nfigConfiguration.java:41)
	at com.commnav.sbh.servlets.ControlServlet.init(ControlServlet.java:90)
.....
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser
	at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:392)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:283)
... 20 more
Root cause: java.lang.ClassCastException:
org.apache.xerces.parsers.SAXParser
	at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:392)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:283)
	at org.jdom.input.SAXBuilder.build(SAXBuilder.java:583)
	at
com.commnav.sbh.framework.config.ServletConfigConfiguration.<init>(ServletCo
nfigConfiguration.java:41)
	at com.commnav.sbh.servlets.ControlServlet.init(ControlServlet.java:90)
....

My frustration comes in that the documentation (HOWTO on ClassLoader) seems
to be very inaccurate, and I am left wondering how the ClassLoaders work,
what I need to configure to seperate these jars or whatever might be needed.

Someone who knows what they're doing... please help me.  I can (and do)
duplicate the error like clockwork.  I'm certain not to be the only one with
this issue and I hope to contribute the solution / explanation to the
community.

thanks,
the llama

------------------------
    Joel P. Worrall
Senior Software Engineer
     CommNav, Inc.
  (717) 796-1936 x274
  jworrall@commnav.com
jpworrall@programmer.net
 home - (717) 796-2314
 Tango the gifted Llama
-------------------------



Mime
View raw message