java.lang.ClassNotFoundException:org.apache.xmlbeans.XmlException

为了读取xlsx文件我正在使用apache POI,我已经下载了zip并将以下jsrs放在我的servlet位置webcontent/web-inf/lib并通过eclipse配置了构建路径

在此处输入图像描述

我的代码如下,

 import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; File uploadedFile = new File(fpath, fileName); item.write(uploadedFile); String mimeType = (Files.probeContentType(uploadedFile.toPath())).toString(); System.out.println(mimeType); if(mimeType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { FileInputStream file = new FileInputStream(uploadedFile); XSSFWorkbook workbook = new XSSFWorkbook(file); for (int i =0; i < workbook.getNumberOfSheets(); i++) { XSSFSheet sheet = workbook.getSheetAt(i); Iterator row = sheet.iterator(); while(row.hasNext()) { Iterator cellIterator = ((Row) row).cellIterator(); while(cellIterator.hasNext()) { Cell cell1 = cellIterator.next(); switch(cell1.getCellType()) { case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell1.getBooleanCellValue() + "\n"); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell1.getNumericCellValue() + "\n"); break; case Cell.CELL_TYPE_STRING: System.out.print(cell1.getStringCellValue() + "\n"); break; } } 

虽然这在eclipse上没有显示和错误,但在我尝试运行代码时会显示以下错误

在此处输入图像描述

我的错是什么? 怎么解决这个?

您需要将XML bean依赖项添加到类路径中。

该库通常称为xmlbeans-xxxjar

将xmlbeans-xpath.jar添加到库中。

我已经下载了最新的poi-3.17二进制文件,xmlbeans-xxxjar包含在下载的软件包中。

附上截图FYR。

xlsx需要主罐子 文件夹ooxml-lib下的xmlbeans-x.x.x.jar