Search code examples
javadependenciesapache-poiclassnotfoundexceptionxssf

I am trying to instantiate XSSFWorkbook, Java throws ClassNotFoundException(cn) (ONLY IN DEBUG)


when I try to instantiate XSSFWorkbook Java throws ClassNotFoundException(cn)

cn value is = "org.apache.xerces.util.SecurityManager"

my code is like this:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

String filePath = "C://fakename.xlsx"

if(Files.exists(Paths.get(filePath))) { 
    FileInputStream fis = null; 
    try { 
        fis = new FileInputStream(new File(filePath));
    } catch (FileNotFoundException e) { 

    }
              
    XSSFWorkbook wb = null;
    
    try { 
                  
        wb = new XSSFWorkbook(fis);
    } 
    catch (Exception ex ) {
        ex.printStackTrace();
    }
              
}

as you may understand I have no problem importing that class or calling it in the code (I can see suggestions by auto-complete (intellisense))

enter image description here

these are the dependencies

I am not a Java developer, Im doing my own researches, tried to change dependencies but nothing yet, in an old project I did use this and I never had a problem.

can someone of you give me some hints, please?

thank you

EDIT: this problem happens only in debugging, it's like if there is a breakpoint in this exception.

enter image description here

but, if I disable it, I can not debug my software anymore.

so weird.


Solution

  • as your development environment also suggests code completion the correct jar must be loaded. Probably your execution environment does not load all the needed jars. In this case the poi-5.0.0.jar and the poi-ooxml-5.0.0.jar must be loaded. The org.apache.poi.xssf package is located in the poi-ooxml-5.0.0.jar file.

    If you make sure that this jar is loaded at execution then everything should be fine. So check your classpath settings in your execution environment.