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

huangapple go评论109阅读模式
英文:

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

  1. import org.apache.logging.log4j.Level;
  2. import org.apache.poi.ss.usermodel.*;
  3. import org.apache.poi.xssf.streaming.SXSSFSheet;
  4. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  5. private Workbook wb;
  6. private void init(String targetPath, String fileName, ExcelExportType exportType) {
  7. // ...
  8. }
  9. public File export() {
  10. // ...
  11. }
  12. according to the link,
  13. [https://xalan.apache.org/xalan-j/][1]
  14. Xalan-Java Version 2.7.3 works with Xerces-Java, and the distribution includes xercesImpl.jar from Xerces-Java 2.12.2.
  15. The Xalan-Java implementation is in xalan.jar and serializer.jar. The SAX, DOM, and JAXP 1.3 interfaces are in xml-apis.jar.
  16. so maybe I need to implement the code in a different way?
  17. any idea how can I solve this?
  18. [1]: https://xalan%202.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

  1. import org.apache.logging.log4j.Level;
  2. import org.apache.poi.ss.usermodel.*;
  3. import org.apache.poi.xssf.streaming.SXSSFSheet;
  4. import org.apache.poi.xssf.streaming.SXSSFWorkbook;
  5. private Workbook wb;
  6. private void init(String targetPath, String fileName, ExcelExportType exportType) {
  7. exportedFile = new File(Paths.get(targetPath, fileName + FILE_EXTENSION).toString());
  8. try {
  9. fileOutputStream = new FileOutputStream(exportedFile);
  10. // if file doesn't exists, then create it
  11. if (!exportedFile.exists()) {
  12. exportedFile.createNewFile();
  13. }
  14. } catch (Exception e) {
  15. throw new RuntimeException("Init failed. File " + exportedFile.getName() + " cannot be found");
  16. }
  17. switch (exportType) {
  18. case MS_EXCEL_2007_AND_UP_STREAMING:
  19. wb = new SXSSFWorkbook();
  20. break;
  21. default:
  22. throw new RuntimeException("Unsupported export type");
  23. }
  24. wb.setMissingCellPolicy(Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
  25. creationHelper = wb.getCreationHelper();
  26. sheet = wb.createSheet(getSheetName());
  27. Font font = wb.createFont();
  28. font.setFontName(DEFAULT_FONT_NAME);
  29. if(sheet instanceof SXSSFSheet) {
  30. ((SXSSFSheet) sheet).trackAllColumnsForAutoSizing();
  31. }
  32. format = wb.createDataFormat();
  33. headerFont = wb.createFont();
  34. headerFont.setFontName(DEFAULT_FONT_NAME);
  35. headerFont.setBold(true);
  36. cellFont = wb.createFont();
  37. cellFont.setFontName(DEFAULT_FONT_NAME);
  38. }
  39. public File export() {
  40. double factor = 390;
  41. for (int i = 0; i < numOfColumns; i++) {
  42. sheet.autoSizeColumn(i);
  43. sheet.setColumnWidth(i, getWidth((int)(maxColumnWidth.get(i) * factor)));
  44. }
  45. sheet.createFreezePane(0,1);
  46. try {
  47. wb.write(fileOutputStream);
  48. fileOutputStream.close();
  49. wb.close();
  50. } catch (IOException e) {
  51. e.printStackTrace();
  52. }
  53. return exportedFile;
  54. }

according to the link,
https://xalan.apache.org/xalan-j/

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

得分: 2

Here is the translation:

通过将这个添加到我的Maven依赖项中进行修复

  1. <dependency>
  2. <groupId>xalan</groupId>
  3. <artifactId>serializer</artifactId>
  4. <version>2.7.3</version>
  5. </dependency>
英文:

fixed by adding this to my maven dependencies

  1. &lt;dependency&gt;
  2. &lt;groupId&gt;xalan&lt;/groupId&gt;
  3. &lt;artifactId&gt;serializer&lt;/artifactId&gt;
  4. &lt;version&gt;2.7.3&lt;/version&gt;
  5. &lt;/dependency&gt;

huangapple
  • 本文由 发表于 2023年6月26日 18:20:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定