java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader

Hello,

I am developing a webwork action that has a reading a xlsx file to use this POI. In implementing the action get the following errors:

[INFO] [talledLocalContainer] Warning: Caught exception attempting to use SAX to load a SAX XMLReader
[INFO] [talledLocalContainer] Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer] Warning: I will print the stack trace then carry on using the default SAX parser
[INFO] [talledLocalContainer] java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer] at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)
[INFO] [talledLocalContainer] at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:74)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:647)

The pom.xml is:

<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>atlassian-jira</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-func-tests</artifactId>
<version>${jira.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>webwork</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
</dependency>
</dependencies>


Any ideas?

Thank you very much!
Patri.

7 answers

I also tried to include the poi libraries to extract Text form various MS Office Formats.
I struggled a while with the dependencies, like you did.
For me, this works. It is a bit different from the snippet above, as I also had to include the poi-scratchpad jar.
POM:
&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi-scratchpad&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
    &lt;exclusions&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;xml-apis&lt;/groupId&gt;
            &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
        &lt;/exclusion&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;dom4j&lt;/groupId&gt;
            &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
        &lt;/exclusion&gt;
    &lt;/exclusions&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;xml-apis&lt;/groupId&gt;
    &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
    &lt;version&gt;1.0.b2&lt;/version&gt;
&lt;/dependency&gt;

Can you paste the code here as well please?

My code is:

protected String doExecute() throws Exception {
FileInputStream fileInputStream = new FileInputStream("D:\\multPartReq12424.xlsx");
XSSFWorkbook workBook = new XSSFWorkbook(fileInputStream);
XSSFSheet sheet = workBook.getSheet("0");
XSSFRow row = null;
XSSFCell cell = null;
for ( int i=0, z=sheet.getLastRowNum(); i<z; i++ ){
row = sheet.getRow(i);
if (row != null) {
for (int ii=0, zz=row.getLastCellNum(); ii<zz; ii++){
cell = row.getCell(i);
if (cell != null) {
if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()){
log.info("CELL STRING: "+cell.getStringCellValue());
}
if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()){
log.info("CELL NUMERIC: "+cell.getStringCellValue());
}
}
}
}
}

return SUCCESS;
}

Thank you very much.

What version of JDK are you using?

are you sure that file is a valid XLSX file, Files exported out of JIRA are not really Excel files but HTML that Excel understands.

Would it be possible to move this out to a test class that you can run stand alone and see

attributes of class

"XSSFWorkbook workBook = new XSSFWorkbook(fileInputStream);"

Thank you very much!

Problem solved.

The problem was libreria.EL pom.xml is as follows:

<dependencies>

<dependency>

<groupId>com.atlassian.jira</groupId>

<artifactId>atlassian-jira</artifactId>

<version>${jira.version}</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.6</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>com.atlassian.jira</groupId>

<artifactId>jira-func-tests</artifactId>

<version>${jira.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>servlet-api</artifactId>

<version>2.5</version>

<scope>provided</scope>

</dependency>

<dependency>

<groupId>opensymphony</groupId>

<artifactId>webwork</artifactId>

<version>1.4</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi</artifactId>

<version>3.8</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml</artifactId>

<version>3.8</version>

<exclusions>

<exclusion>

<groupId>xml-apis</groupId>

<artifactId>xml-apis</artifactId>

</exclusion>

<exclusion>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>xml-apis</groupId>

<artifactId>xml-apis</artifactId>

<version>1.0.b2</version>

</dependency>

</dependencies>

hi, i think i have a similar problem.

also the classCastException.

How exactly did you solve this?

I also tried to include the poi libraries to extract Text form various MS Office Formats.

I struggled a while with the dependencies, like you did.

For me, this works. It is a bit different from the snippet above, as I also had to include the poi-scratchpad jar.

POM:

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi-scratchpad&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;org.apache.poi&lt;/groupId&gt;
    &lt;artifactId&gt;poi-ooxml&lt;/artifactId&gt;
    &lt;version&gt;3.8&lt;/version&gt;
    &lt;exclusions&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;xml-apis&lt;/groupId&gt;
            &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
        &lt;/exclusion&gt;
        &lt;exclusion&gt;
            &lt;groupId&gt;dom4j&lt;/groupId&gt;
            &lt;artifactId&gt;dom4j&lt;/artifactId&gt;
        &lt;/exclusion&gt;
    &lt;/exclusions&gt;
&lt;/dependency&gt;

&lt;dependency&gt;
    &lt;groupId&gt;xml-apis&lt;/groupId&gt;
    &lt;artifactId&gt;xml-apis&lt;/artifactId&gt;
    &lt;version&gt;1.0.b2&lt;/version&gt;
&lt;/dependency&gt;

Hello,

I am having the same problem.

I have a pom.xml roughly the same as yours and it i still got the error...

My error :

[INFO] [talledLocalContainer] Warning: Caught exception attempting to use SAX to load a SAX XMLReader
[INFO] [talledLocalContainer] Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer] Warning: I will print the stack trace then carry on using the default SAX parser
[INFO] [talledLocalContainer] java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
[INFO] [talledLocalContainer] at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)
[INFO] [talledLocalContainer] at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:74)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:647)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:530)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXReader.read(SAXReader.java:309)
[INFO] [talledLocalContainer] at org.dom4j.io.SAXReader.read(SAXReader.java:261)

...

My pom.xml :

<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>atlassian-jira</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-func-tests</artifactId>
<version>${jira.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>webwork</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.0</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.healthmarketscience.jackcess</groupId>
<artifactId>jackcess</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>

Any hint or any ideas ?

Thank you

hi, i think i have a similar problem.

also the classCastException.

How exactly did you solve this?

Hi All , i am facing same exception. can some help me ? 

Log Info :

*************** False/True***********true
WARNING: Cannot load DocumentFactory: com.atlassian.core.xml.InterningDocumentFa
ctory
Warning: Caught exception attempting to use SAX to load a SAX XMLReader
Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.
SAXParser cannot be cast to org.xml.sax.XMLReader
Warning: I will print the stack trace then carry on using the default SAX parser

java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast
to org.xml.sax.XMLReader
at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:74)
at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:647)
at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:530)
at org.dom4j.io.SAXReader.read(SAXReader.java:309)
at org.dom4j.io.SAXReader.read(SAXReader.java:261)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContent
TypesFile(ContentTypeManager.java:377)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(Conte
ntTypeManager.java:105)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(Zi
pContentTypeManager.java:56)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:
137)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:623)

at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:230)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:1
87)
at com.vodafonermtool.releasecalendar.excel.report.ReleaseCalendarExcelS
heet.write(ReleaseCalendarExcelSheet.java:144)
at com.vodafonermtool.releasecalendar.excel.report.MyPluginComponentImpl
.doGet(MyPluginComponentImpl.java:263)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at com.atlassian.plugin.servlet.DelegatingPluginServlet.service(Delegati
ngPluginServlet.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at com.atlassian.plugin.servlet.ServletModuleContainerServlet.service(Se
rvletModuleContainerServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:208)

 

My POM.XML file

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.vodafonermtool.releasecalendar.excel.report</groupId>
<artifactId>RM-release-menu</artifactId>
<version>1.0</version>

<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>

<name>jira-reports-menu</name>
<description>This is the com.vodafonermtool.releasecalendar.excel.report:jira-reports-menu plugin for Atlassian JIRA.</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>            <!--- used 3.10 FINAL version as well -->
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.5</version>     
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.8</version>        <!--- used 3.10 FINAL version as well -->
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>      
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.8</version>                   <!--- used 3.10 FINAL version as well -->
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.8</version>
</dependency>

<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>

<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
</dependency>

<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
</dependency>

<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>

</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

<properties>
<jira.version>6.4.4</jira.version>
<amps.version>5.0.13</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<testkit.version>5.2.26</testkit.version>
</properties>

</project>

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

1,203 views 17 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you