NoClassDefFoundError从csv转换为Excel时

我得到这个例外

线程“main”中的exceptionjava.lang.NoClassDefFoundError:org / apache / xmlbeans / XmlException at com.restcalls.JSONtoCSV.main(JSONtoCSV.java:176)

当我试图将csv文件转换为excel文件。 这行似乎是造成这个问题 – XSSFWorkbook workBook = new XSSFWorkbook();

我已经添加了最新的POI jar – 3.17,这是我的代码:

 String xlsxFileAddress = "C:/Users/xxxxx/REST/exports/test.xlsx"; //xlsx file address System.out.println("here 0"); XSSFWorkbook workBook = new XSSFWorkbook(); System.out.println("here 0.1"); XSSFSheet sheet = workBook.createSheet("sheet1"); System.out.println("here 1"); String currentLine=null; int RowNum=0; BufferedReader br = new BufferedReader(new FileReader(csvFileAddress)); System.out.println("here 2: "+br); while ((currentLine = br.readLine()) != null) { String str[] = currentLine.split(","); RowNum++; XSSFRow currentRow=sheet.createRow(RowNum); for(int i=0;i<str.length;i++){ currentRow.createCell(i).setCellValue(str[i]); } } FileOutputStream fileOutputStream = new FileOutputStream(xlsxFileAddress); workBook.write(fileOutputStream); fileOutputStream.close(); System.out.println("Done"); 

您需要下载并将XML bean依赖项添加到您的类path中。 该库通常被称为xmlbeans-xxxjar。 例如:search并下载xmlbeans-2.6.0.jar或者如果你有一个Maven项目设置POM如下

  <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.6.0</version> </dependency>