java.lang.ClassNotFoundException: org.apache.xml.serializer.OutputPropertiesFactory is thrown after upgrading xalan to 2.7.3

I have java code that exports some data into an excel file. ( I only included below what I think are the relevant parts in the code)

Everything worked fine but then I upgraded my xalan from 2.7.2 to 2.7.3 and it stoped working. the reason - java.lang.ClassNotFoundException: org.apache.xml.serializer.OutputPropertiesFactory

The exception is thrown at the 'wb.write(fileOutputStream);' line under the export() method

import org.apache.logging.log4j.Level; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; private Workbook wb; private void init(String targetPath, String fileName, ExcelExportType exportType) { exportedFile = new File(Paths.get(targetPath, fileName + FILE_EXTENSION).toString()); try { fileOutputStream = new FileOutputStream(exportedFile); // if file doesn't exists, then create it if (!exportedFile.exists()) { exportedFile.createNewFile(); } } catch (Exception e) { throw new RuntimeException("Init failed. File " + exportedFile.getName() + " cannot be found"); } switch (exportType) { case MS_EXCEL_2007_AND_UP_STREAMING: wb = new SXSSFWorkbook(); break; default: throw new RuntimeException("Unsupported export type"); } wb.setMissingCellPolicy(Row.MissingCellPolicy.CREATE_NULL_AS_BLANK); creationHelper = wb.getCreationHelper(); sheet = wb.createSheet(getSheetName()); Font font = wb.createFont(); font.setFontName(DEFAULT_FONT_NAME); if(sheet instanceof SXSSFSheet) { ((SXSSFSheet) sheet).trackAllColumnsForAutoSizing(); } format = wb.createDataFormat(); headerFont = wb.createFont(); headerFont.setFontName(DEFAULT_FONT_NAME); headerFont.setBold(true); cellFont = wb.createFont(); cellFont.setFontName(DEFAULT_FONT_NAME); } public File export() { double factor = 390; for (int i = 0; i < numOfColumns; i++) { sheet.autoSizeColumn(i); sheet.setColumnWidth(i, getWidth((int)(maxColumnWidth.get(i) * factor))); } sheet.createFreezePane(0,1); try { wb.write(fileOutputStream); fileOutputStream.close(); wb.close(); } catch (IOException e) { e.printStackTrace(); } return exportedFile; } 

according to the link,

Xalan-Java Version 2.7.3 works with Xerces-Java, and the distribution includes xercesImpl.jar from Xerces-Java 2.12.2.

The Xalan-Java implementation is in xalan.jar and serializer.jar. The SAX, DOM, and JAXP 1.3 interfaces are in xml-apis.jar.

so maybe I need to implement the code in a different way? any idea how can I solve this?

1 Answer

fixed by adding this to my maven dependencies

 <dependency> <groupId>xalan</groupId> <artifactId>serializer</artifactId> <version>2.7.3</version> </dependency> 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like