POI Version : 3.12
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version> <scope>compile</scope> </dependency>
I am trying to parse an excel Sheet attachment. The parsing of excel sheet is failing with class cast exception
java.lang.ClassCastException: com.ctc.wstx.stax.WstxEventFactory cannot be cast to javax.xml.stream.XMLEventFactory
The excel sheet is parsing correctly when i use junit.
Code to parse:
workbook = new XSSFWorkbook(fs);
fs - FileInputStream
Community moderators have prevented the ability to post new answers.
Dear Kauhik,
please try the following exclusion:
<exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions>
For example:
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.12</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.12</version> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> </exclusions> </dependency>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, can I ask what version of Jira you are using. I'm using 6.4.2 with dependency in Jira-core api and it give me CastException later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I deployed my plugin on the 3 JIRA machines: 6.3.3 , 6.3.15 and 6.4. I got some errors at first but after cleaning the project, it worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If anyone searches for the answer in Confluence, here's my pom.xml.
I'm not saying it's perfect, I'm saying it works today with Confluence, and examples may help someone else. Thank you everyone for your examples in JIRA, it actually helped me a lot.
<project ...> <modelVersion>4.0.0</modelVersion> <groupId>com.playsql</groupId> <artifactId>play-sql-export-addon</artifactId> <version>1.1-SNAPSHOT</version> <packaging>atlassian-plugin</packaging> <dependencies> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.14</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.atlassian.confluence</groupId> <artifactId>confluence</artifactId> <version>${confluence.version}</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> </exclusion> <exclusion> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> </exclusion> <exclusion> <groupId>javax.xml.stream</groupId> <artifactId>stax-api</artifactId> </exclusion> <exclusion> <groupId>org.codehaus.woodstox</groupId> <artifactId>wstx-asl</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <repositories> <repository> <id>codehaus-mule-repo</id> <name>codehaus-mule-repo</name> <url>https://repository-master.mulesoft.org/nexus/content/groups/public/</url> <layout>default</layout> </repository> </repositories> <build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-amps-plugin</artifactId> <version>6.0.8</version> <extensions>true</extensions> <configuration> <systemPropertyVariables> <upm.pac.disable>true</upm.pac.disable> </systemPropertyVariables> <enableFastdev>false</enableFastdev> <instanceId>confluence</instanceId> <installPlugin>false</installPlugin> <cliPort>4338</cliPort> <httpPort>1991</httpPort> <contextPath>/confluence</contextPath> <products> <product> <id>confluence</id> <instanceId>confluence</instanceId> <version>${confluence.version}</version> <dataVersion>${confluence.data.version}</dataVersion> <containerId>tomcat7x</containerId> </product> </products> <instructions> <!-- Yes, all this plugin does is use Apache POI and export a reduced com.playsql.psea.api API to build Excel files. It's a light API which can be shared between all my plugins and not weigh 20Mb and cause ClassCastExceptions each time I include it ;) --> <Export-Package> com.playsql.psea.api </Export-Package> <Import-Package> com.google.common.collect;version="0.0.0", com.atlassian.confluence.core;version="0.0.0", org.xml.sax*;version="0.0.0", org.w3c.dom*;version="0.0.0", com.ctc.wstx*;version="0.0.0", javax.xml*;version="0.0.0" </Import-Package> </instructions> </configuration> </plugin> </plugins> </build> <properties> <java.version>1.8</java.version> <upm.license.compatibility.version>2.8.1</upm.license.compatibility.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <allowGoogleTracking>false</allowGoogleTracking> <jira.version>7.0.0</jira.version> <confluence.version>5.8.6</confluence.version> <confluence.data.version>5.8.6</confluence.data.version> <plugin.create.content.version>5.2.1</plugin.create.content.version> <ao.version>0.28.1</ao.version> <amps.version>6.0.8</amps.version> <plugin.testrunner.version>1.2.3</plugin.testrunner.version> <skipTests>false</skipTests> </properties> </project>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jens,
Thanks a lot. I added stax-api as you told. I also added xml-api because i was getting further class cast exceptions.
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}</version> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> </exclusions> <scope>compile</scope> </dependency>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I'm also struggling with JIRA 6.4.2 and the pom to get Apache-poi to work.
After some exlusion I still get :
java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
Read from somewhere I found out this error because of outdated Xerces implementation.
This is my POM right now which I have above error:
<dependency> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> <version>1.0.b2</version> </dependency> <dependency> <groupId>xmlpull</groupId> <artifactId>xmlpull</artifactId> <version>1.1.3.1</version> </dependency> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.3.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans-xpath</artifactId> <version>2.3.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>net.sf.saxon</groupId> <artifactId>saxon</artifactId> <version>8.7</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.9</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.9</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> <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-scratchpad</artifactId> <version>3.9</version> <scope>compile</scope> <exclusions> <exclusion> <groupId>stax</groupId> <artifactId>stax-api</artifactId> </exclusion> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> <exclusion> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> </exclusion> </exclusions> </dependency>
I know I should not be this complicated but I out of my mind right now after too much re-run the plugin. Any help is appreciated.
Best regards,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you use Eclipse, I would suggest you to check list "Resolved Dependencies" on tab "Dependency Hierarchy" for any duplicates. In your case, I think that, for example, dom4j is already provided by JIRA and you must not add it as a dependency. And there could be more duplicates. BTW - Would it be an option for you to switch from POI 3.9 to 3.12?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also get another strange error when using 3.12 because of the XML library, NoClassDefFound exception but i can't remember exactly... Forgot to mention I also use jira-core library in my plugin. It add up a lot of XML libraries (including dom4j and xercesImpl). I will try to use Resolved dependencies ( I did use maven dependency::tree) but I don't think I will show the full picture because I use OBR instead of jar... It's very difficult to guess what it's already there in the depedency tree when the plugin is started.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.