从 Java NoClassDefFoundError 写入 Excel

Write in Excel from Java NoClassDefFoundError

当我尝试从 Java Ant 添加数据到 Excel 时,它显示 NoClassDefFoundError,即使我导入了 Apache Poi 的所有 Jar 文件。这是错误:

Exception in thread "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 导入文件:

问题解决了!看来我还需要在导入 jar 文件后向 build.xml 添加依赖项!