java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException [英] java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException

查看:72
本文介绍了java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In order to read an xlsx file I'm using apache POI, I've downloaded the zip and placed the following jsrs in my servlet location webcontent/web-inf/lib and configured build path through 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> row = sheet.iterator();
       while(row.hasNext()) {
   Iterator<Cell> 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 上没有显示和错误,但当我尝试运行代码时,它显示了以下错误

Though this does not show and errors on eclipse it shows the following errors when I try to run the code

我的错误是什么?如何解决这个问题?

What is my mistake? How to solve this?

推荐答案

您需要添加 XML bean依赖于你的类路径.

You need to add the XML beans dependency to your class path.

该库通常称为xmlbeans-x.x.x.jar

这篇关于java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆