This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Cannot load xerces SAXParser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Cannot load xerces SAXParser" Watch "Cannot load xerces SAXParser" New topic
Author

Cannot load xerces SAXParser

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hello,

I have some serious problems with Xerces2 Java Parser 2.9.1.

I am using Apache Tomcat/5.5.25 JVM 1.5.0_16-b02.

I just downloaded Xerces2 version 2.9.1. I copied the following jar files into the library called: /apache-tomcat-5.5.25/shared/lib/ :

resolver.jar
serializer.jar
xercesImpl.jar
aml-apis.jar

When I restart the container it seems to work fine. But it only works until I reload my application using Tomcat Web Application Manager. Then I get this error:
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

I have searched the internet to solve the problem. It seems that several people have experienced the same problem, but I´m not sure how to work around this issue.

Any help please would be appreciated?

Log print from wrapper.log:

Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

Why are you explicitly using Xerces version 2.9.1 as a shared library? The JAXP 1.3 implementation included the Java release you're using already uses the Xerces parser (albeit version 2.6.2) by default.
From the log file I see you're using the JDOM API. Itss SAXBuilder class will, by default, use JAXP to retrieve a parser. So based on just this information I don't really see the need to include the shared library.
Shared libraries are something to be very cautious about anyway, but especially in case of an XML parser implementation.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Thanks, it works now :-)

I removed the file called xercesImpl.jar. Then I added a previous installed jar file called xerces.jar and it works now.


Jelle Klap wrote:Why are you explicitly using Xerces version 2.9.1 as a shared library? The JAXP 1.3 implementation included the Java release you're using already uses the Xerces parser (albeit version 2.6.2) by default.
From the log file I see you're using the JDOM API. Itss SAXBuilder class will, by default, use JAXP to retrieve a parser. So based on just this information I don't really see the need to include the shared library.
Shared libraries are something to be very cautious about anyway, but especially in case of an XML parser implementation.
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hello,

I just realized, that I still have a problem with my code.

As mentioned in my previous message I tried to remove all the jar files from Xerces version 2.9.1 package. I removed the following files from tomcat/shared/lib and restarted the container:

xercesImpl.jar.
xml-apis.jar
serializer.jar
resolver.jar

I also removed xerces.jar from tomcat/shared/lib

Without xerces.jar (after restarting the container) and got the following an error:

I then added the xerces.jar again and it works until I restart the application with Tomcat web application manager. Now I get the following errors:


It seems to be a org.jdom.JDOMException:
- Could not load org.apache.xerces.parsers.SAXParser: SAX2 driver class org.apache.xerces.parsers.SAXParser not found...

I'm not sure how to work around this issue? As I understood on the last reply, I was told to remove the Xerces package,
because the JDOM API by default is using the JAXP to retrieve a parser. I removed the Xerces version 2.9.1 package,
but is still getting a org.jdom.JDOMException?

Here is some of the other jar files placed in the tomcat/shared/lib:

xml-apis.jar
xerces.jar
xalan.jar
saxpath.jar
jdom.jar
jaxrpc.xml
jaxen-jdom.jar
jaxen-core.jar
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

You don't need any of those dependency libraries I think.
JAXP 1.3 includes a SAX 2.0.2 parser, which JDOM requires (the Xerces dependency), but it also supports XPath and XSLT (the Jaxen and Xalan dependency JARs).
I'm prretty sure you can clear the shared/lib folder completely of JDOM dependencies. Also, I'd suggest moving the jdom.jar file itself to the WEB-INF/lib folder of the specific web application(s) that require(s) it, instead of making it a shared library.
isuru chamarasinghe
Greenhorn

Joined: Aug 21, 2008
Posts: 12
I faced with the same issue when trying to pass an XML file using org.apache.xerces.parsers.SAXParser.

After goggling for a while came with the below solution.

I downloaded the latest release of Xerces-J-bin.X.XX.X.zip and copied the xercesImpl.jar to the ext folder under jre6.

1. In my case I download Xerces-J-bin.2.11.0.zip from http://www.apache.org/dist/xerces/j/Xerces-J-bin.2.11.0.zip URL.

2. Unzipped and copy the xercesImpl.jar file to C:\Program Files\Java\jre6\lib\ext

Please note, this can be accomplished by adding the xercesImpl.jar into your class-path as a dependency as well.


Isuru Chamarasinghe.
BIT (C.Sturt), SCJP, SCWCD, SCBCD, A+, OCA
John McDonnell
Greenhorn

Joined: Mar 24, 2011
Posts: 6

isuru chamarasinghe wrote:I faced with the same issue when trying to pass an XML file using org.apache.xerces.parsers.SAXParser.

After goggling for a while came with the below solution.

I downloaded the latest release of Xerces-J-bin.X.XX.X.zip and copied the xercesImpl.jar to the ext folder under jre6.

1. In my case I download Xerces-J-bin.2.11.0.zip from http://www.apache.org/dist/xerces/j/Xerces-J-bin.2.11.0.zip URL.

2. Unzipped and copy the xercesImpl.jar file to C:\Program Files\Java\jre6\lib\ext

Please note, this can be accomplished by adding the xercesImpl.jar into your class-path as a dependency as well.


I've tried adding it to my class path and I was having no luck. I then spotted this post, and stuck the jar in the lib/ext folder and everything worked.

How do you mean "into your class-path as a dependency"


OCPJP - 68%
KiranPatel JavaKnowledge
Greenhorn

Joined: Aug 09, 2013
Posts: 1
I was facing the same issue, It was solved only when I replaced xerces-1.4.jar file with a newer version xerces-2.6.2 jar
 
GeeCON Prague 2014
 
subject: Cannot load xerces SAXParser