WanderlandWanderland |
|
Friday Jul 18, 2008
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
If your application suddenly stops working with the stack trace below: Caused by: java.lang.ClassNotFoundException:
org.apache.xerces.parsers.SAXParser
You might be wondering if different class loaders keep separate copies of xercesImpl.jar or if you need to provide xercesImpl.jar to your application to let it find org.apache.xerces.parsers.SAXParser, but it has worked before without adding xercesImpl.jar. The answer: Glassfish does not have a xercesImpl.jar in its system classloader and you most likely will not need this jar. The reason is when system property org.xml.sax.driver is not specified and also no jars provide service API for org.xml.sax.driver , org.xml.sax.helpers.XMLReaderFactory.createXMLReader resolves to use a default XMLReader class which is SAX Parser specific. In SUN JDK5, the default class is com.sun.org.apache.xerces.internal.parsers.SAXParser. Therefore, if another application changes the system property of org.xml.sax.driver and points it to org.apache.xerces.parsers.SAXParser, your application will fail with ClassNotFoundException. How to resolve this issue without adding xercesImpl.jar? You might unset the system property org.xml.sax.driver in your application when you try to get an XMLReader, or you may use a fall-back mechanism like below:
Note that it is generally not a good idea to hard code a reference com.sun.org.apache.xerces.internal.parsers.SAXParser in your application, because the class might not be available when JDK upgrades or in other distributions of JDK .
Posted at 05:07PM Jul 18, 2008 by Mei Wu in Sun | Comments[1] |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||