Issue
I have downloaded the latest release of poi-5.0.0 and add the external jar to the Java Project. Here is the code:
import java.io.*;
import org.apache.poi.hssf.usermodel.*;
public class Test {
public static void main(String[] args) {
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("FirstSheet");
FileOutputStream fileOut = new FileOutputStream("NewExcelFile1.xlsx");
workbook.write(fileOut);
fileOut.close();
System.out.println("Success");
} catch (IOException e) {
e.printStackTrace();
}
}
}
The Error I am getting is:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook at test3.Test.main(Pleease.java:11) Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ... 1 more
Could not find the solution for this issue on the internet so I would be very happy to find it here. Thanks in advance!
Solution
Reproduced this. When you are adding apache .jar file dependencies after right clicking on the Project -> Properties -> Java Build Path, make sure you are adding the .jars to the ClassPath and not Modulepath. If you add them to the Modulepath, this error shows up. Also if you have a module dependencies class, recreate your eclipse project and deselect the "Generate module" option checkbox. This is a work around until modules are sorted out.
Answered By - Christopher Hoffman
Answer Checked By - Marilyn (JavaFixing Volunteer)