當我嘗試從 Java Ant 向 Excel 添加資料時,它顯示NoClassDefFoundError
,即使我匯入了 Apache Poi 的所有 Jar 檔案。這是錯誤:
執行緒“main”中的例外 java.lang.NoClassDefFoundError:org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream
這是我試過的代碼:
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("Sheet1");
XSSFRow row = sheet.createRow(0);
Cell cell0 = row.createCell(0);
cell0.setCellValue("HelloWorld!");
try{
FileOutputStream out = new FileOutputStream(new File("Result.xlsx"));
wb.write(out);
out.close();
System.out.println("Done");
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
這些是 Jar 匯入的檔案:
uj5u.com熱心網友回復:
問題解決了!看來我還需要在匯入 jar 檔案后向 build.xml 添加依賴項!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/462471.html
標籤:爪哇 擅长 摇摆 罐 apache-poi