Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFoundException, even though the containing JAR is part of the build

I am getting a ClassNotFoundException on a class (HSSFWorkbook) that is included in a JAR that is included in my build. The JAR is listed in this list (I am using Eclipse):

Project -> Properties -> Java Build Path -> Libraries

I have tried removing and adding it again, to no avail.

My code is as follows:

// ...
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
// ...

public class XLSWorkbook {
    private HSSFWorkbook wb = null;

    // ...
    public XLSWorkbook() {
        wb = new HSSFWorkbook();
    }
}

And the exception is thrown when I try to instantiate the XLSWorkbook class. The JAR I am using is the POI library from Apache (to be precise: poi-3.8-20120326.jar).

like image 887
Bart Friederichs Avatar asked Feb 19 '23 05:02

Bart Friederichs


2 Answers

Since ADT-18 (I am not sure about the version), external jar libraries have not to be included explicitly. You should put it inside the libs folder . ADT will provide to import they for you. So you should remove the libraries from Project -> Properties -> Java Build Path -> Libraries

like image 156
Blackbelt Avatar answered Feb 20 '23 18:02

Blackbelt


What class is not found? Looks like you are developing for Android. This means classpath at runtime is not the same as at build time. You can have all your jars in place while compiling while this can be wrong while running.

like image 28
Dims Avatar answered Feb 20 '23 19:02

Dims