Hi,
I've added the Apache POI dependency to my JIRA plugin in order to add the ability to create Excel spreadsheets.
I've been able to create a simple spreadsheet with data populated in cells using the HSSFWorkbook. But when I change my code to use the XSSFWorkbook (instead of HSSFWorkbook, all other code unchanged), then I'm getting the following run-time error:
java.util.ServiceConfigurationError: javax.xml.stream.XMLEventFactory: Provider com.ctc.wstx.stax.WstxEventFactory not found
// Workbook workbook = new HSSFWorkbook(); // this works
Workbook workbook = new XSSFWorkbook(); // this gets the run-time error
Can this be some sort of jar conflict?
Here is the Apache POI dependency that I added to my pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
I looked up the jar that has the com.ctc.wstx.stax.WstxEventFactory class and it belongs to wstx-asl-x.x.x.jar ... do I need to add a dependency to this? Or add it to the Import-Package section?
Thanks in advance for any help!
I found the solution! I added another dependency (a jar library which contains the com.ctc.wstx.stax.WstxEventFactory class) so the following is what I needed in my pom.xml:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>com.ctc.wstx</groupId>
<artifactId>woodstox-osgi</artifactId>
<version>3.2.1.1</version>
</dependency>
What fixed it for me was having following dependencies:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
<scope>provided</scope>
</dependency>
<!-- BE AWARE! It is absolutely crucial for wstx-asl to be bundled with plugin although it is present in Jira as well. -->
<!-- Jira version is not exported and it is a known bug: https://jira.atlassian.com/browse/JRASERVER-26214 -->
<!-- This artifact is supplemental for Apache POI library. -->
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>wstx-asl</artifactId>
<version>3.2.4</version>
</dependency>
And running creation of XSSFWorkbook in different context:
XSSFWorkbook xssfWorkbook;
try {
xssfWorkbook = ContextClassLoaderSwitchingUtil.runInContext(WstxEventFactory.class.getClassLoader(), (Callable<XSSFWorkbook>) XSSFWorkbook::new);
} catch (Exception e) {
throw new IllegalStateException("Cannot create XLSX workbook with WstxEventFactory class loader.");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.