Issue
I have a project which involves writing to an Excel spreadsheet (.xlsx) using Apache POIs XSSFWorkbook() class.
It worked fine in a previous version of Apache POI for Java 8. Recently we migrated our code base to OpenJDK 11 and updated our Maven version for Apache POI to 4.1.0 as designated in the FAQ Apache POI FAQ.
Within Eclipse itself it is able to generate excel sheets to my Desktop as expected (on a Win 7 machine). However after doing a maven package into the jar file, the jar version does not work.
Am I compiling this wrong somehow? Snippet below (does not contain all the classes as there are a bunch of other classes which read in data from a different source)
private Workbook getWorkbook(String excelFilePath)
throws IOException, EncryptedDocumentException, InvalidFormatException {
Workbook workbook = null;
if (excelFilePath.endsWith("xlsx")) {
workbook = new XSSFWorkbook();
//} else if (excelFilePath.endsWith("xls")) {
//workbook = new HSSFWorkbook();
} else {
throw new IllegalArgumentException("The specified file is not Excel file");
}
return workbook;
}
public void writeReport(String excelFilePath) throws Exception {
workbook = getWorkbook(excelFilePath);
createHelper = workbook.getCreationHelper();
//Summary Sheet
TCOTSummarySheet summarySheet = new TCOTSummarySheet(workbook);
summarySheet.setProject(PROJECT);
summarySheet.setMaps(headerInfo, reportInfo, queryLinks);
summarySheet.createSheet();
//Bug Breakdown Sheet
if (bugBreakdownFlag) {
TCOTBugBreakdownSheet bugBreakdownSheet = new TCOTBugBreakdownSheet(workbook);
bugBreakdownSheet.setSummarySheet(summarySheet);
bugBreakdownSheet.setMaps(headerInfo, reportInfo, queryLinks);
bugBreakdownSheet.createSheet();
}
//Complete Write
try (FileOutputStream outputStream = new FileOutputStream(excelFilePath)) {
workbook.write(outputStream);
}
catch (Exception e) {
System.out.println(e.getLocalizedMessage());
}
workbook.close();
}
EDIT:
To give more context into the overarching project it is a JavaFX project written in OpenJDK 11.
This particular portion involves running a Swing application executed from JavaFX. This Swing application is actually the one using Apache POI to generate Excel Reports. Is this possibly due to a threading issue?
EDIT 2: Added picture of stack trace
EDIT 3: I have tried adding javax dependencies to my pom.xml and also tried adding them as referenced external libraries but to no avail.
<!-- JAXB/Javax Dependencies -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.4.0-b180830.0359</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.activation/javax.activation-api -->
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
I've been compiling with maven package.
Solution
The issue was that the custom runtime image did not include jdk.charsets
jdk.charsets needs to be included when using the jlink application in creating runtimes used by apache poi.
Answered By - Chris Toh
Answer Checked By - Mary Flores (JavaFixing Volunteer)