Apache 中的 NoClassDefFoundError POI/FileOutputStream

NoClassDefFoundError in Apache POI/FileOutputStream

当我尝试 运行 下面的代码时,出现 NoClassDefFoundError 错误。我检查了大量类似的帖子,但没有帮助。我做错了什么?我想,FileOutputStream 有一些东西,但我不知道是什么。

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {


        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("Vienna");
        File viennaBatch = new File("C:\Users\majan\Desktop\CitiJanus\Vienna.xls");
        viennaBatch.createNewFile();
        Row row = sheet.createRow(1);
        Cell cell = row.createCell(1);
        cell.setCellValue("a");

        
        FileOutputStream fileOut
                = new FileOutputStream("C:\Users\majan\Desktop\CitiJanus\Vienna.xls");
        workbook.write(fileOut);
        fileOut.close();
    }
}```

error:

```Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
    at org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59)
    at org.apache.poi.poifs.property.DirectoryProperty.<init>(DirectoryProperty.java:52)
    at org.apache.poi.poifs.property.RootProperty.<init>(RootProperty.java:31)
    at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:58)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:99)
    at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:121)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1357)
    at Main.main(Main.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 8 more```



引自the POI page

Apache commons-math3 and commons-compress were added as a dependency in POI 4.0.0. Zaxxer SparseBitSet was added as a dependency in POI 4.1.2

您收到的异常表明类路径中缺少 commons-math3。