Bug 57414 - Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
Summary: Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuild...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: SXSSF (show other bugs)
Version: 3.11-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-05 13:52 UTC by Amit Lodha
Modified: 2015-03-23 21:49 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Amit Lodha 2015-01-05 13:52:07 UTC
hi,
while writing xssf file, i am getting a Exception saying 
Caused by: java.lang.ClassCastException: Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
	at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
	at org.apache.poi.util.DocumentHelper.<clinit>(DocumentHelper.java:52)
	... 121 more



Details:

pom.xml

		<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.11</version>
		</dependency>

		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.11</version>
			<exclusions>
				<!-- STAX comes with Java 1.6 -->
				<exclusion>
					<artifactId>stax-api</artifactId>
					<groupId>javax.xml.stream</groupId>
				</exclusion>
				<exclusion>
					<artifactId>stax-api</artifactId>
					<groupId>stax</groupId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>dom4j</groupId>
			<artifactId>dom4j</artifactId>
			<version>1.6.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-stax-api_1.2_spec</artifactId>
			<version>1.2</version>
		</dependency>

		<dependency>
			<groupId>org.codehaus.woodstox</groupId>
			<artifactId>woodstox-core-lgpl</artifactId>
			<version>4.4.1</version>
		</dependency>
		<dependency>
			<groupId>xerces</groupId>
			<artifactId>xerces</artifactId>
			<version>2.4.0</version>
		</dependency>
		<dependency>
			<groupId>xerces</groupId>
			<artifactId>xmlParserAPIs</artifactId>
			<version>2.6.2</version>
		</dependency>

		<dependency>
			<groupId>xerces</groupId>
			<artifactId>xercesImpl</artifactId>
			<version>2.11.0</version>
		</dependency>



Library Inside war:

 xercesImpl-2.4.0.jar
 xml-apis-1.3.04.jar
 xml-apis-ext-1.3.04.jar
Comment 1 Nick Burch 2015-01-05 16:25:00 UTC
That looks a very complicated pom file, and if your project is just doing POI stuff, it contains lots of things that aren't needed, and most likely one of those is breaking it

You should be fine with just:


		<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.11</version>
		</dependency>

		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.11</version>
		</dependency>

No need for any exclusions with 3.11, no need for anything else!
Comment 2 Amit Lodha 2015-01-06 07:37:40 UTC
i tried the same but now i am getting below error

 	org/xml/sax/SAXException: java.lang.NoClassDefFoundError: org/xml/sax/SAXException
Comment 3 Dominik Stadler 2015-03-23 21:49:12 UTC
These are included in Java 6 and newer, so it seems you are either using a Java prior to 6 (which is not supported any more by POI), or the JRE that you are using is not fully conforming to standards, e.g. we had similar problems with IBM JDK, where using IBM JDK 7 resolved problems.

Please review http://poi.apache.org/faq.html#faq-N1017E and see if the suggestions there make it work. 

For now I cannot see any problem in POI, therefore I am closing this as WORKSFORME, please reopen with more information and full code to reproduce the error if you still think this is caused by POI itself.