问题
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

and my code looks as follows,
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;
}
}
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?
回答1:
You need to add the XML beans dependency to your class path.
The library is usually called xmlbeans-x.x.x.jar
回答2:
I have downloaded the latest poi-3.17 binaries and xmlbeans-x.x.x.jar is included in the downloaded package itself.
Attached the screenshots FYR.
回答3:
Add xmlbeans-xpath.jar to your libraries.
来源:https://stackoverflow.com/questions/23080945/java-lang-classnotfoundexception-org-apache-xmlbeans-xmlexception