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

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

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) {
    // ...
}

public File export() {
    // ...
}

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

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]: 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

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,
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依赖项中进行修复

<dependency>
    <groupId>xalan</groupId>
    <artifactId>serializer</artifactId>
    <version>2.7.3</version>
</dependency>
英文:

fixed by adding this to my maven dependencies

    &lt;dependency&gt;
        &lt;groupId&gt;xalan&lt;/groupId&gt;
        &lt;artifactId&gt;serializer&lt;/artifactId&gt;
        &lt;version&gt;2.7.3&lt;/version&gt;
    &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:

确定