Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Apache POI not working in JIRA Plugin

kaushikk July 6, 2015

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

 

 

 

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Jens Goetz July 15, 2015

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>
Andrei RIPA August 4, 2015

This works great!

nguyen_micheal August 5, 2015

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.

Andrei RIPA August 5, 2015

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.

1 vote
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 22, 2016

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>
0 votes
kaushikk July 23, 2015

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>
Nikolay November 17, 2015

what's your ${poi.version}?

0 votes
nguyen_micheal July 22, 2015

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,

Jens Goetz July 22, 2015

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?

nguyen_micheal July 27, 2015

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events