Bhavik Shah
Bhavik Shah

Reputation: 5183

NoClassDefFound Exception

I am using apache poi to open an existing excel file.

public static int generateReport(Calendar csdate,Calendar cedate) throws Exception
{
     FileInputStream fileIn =null;
     FileOutputStream fileOut = null;
     int sum=0;//For calculating the total number of tickets
    final Workbook wb;
    fileIn =new FileInputStream("d:\\excelfiles\\TicketsReport.xlsm");
    wb = org.apache.poi.ss.usermodel.WorkbookFactory.create(fileIn);<-- Exception
    final Sheet sheet = wb.getSheet("Report");
    //rest of stuff
}

I have a servlet which takes the dates from an html page and call generateReport(). The problem is this program was running previously with same tomcat 6 version and servlet2.4 version.In eclipse there is no compile time error at the WorkbookFactory.create() line. Here's the stack trace.

java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/WorkbookFactory
at ReportFromJira.generateReport(ReportFromJira.java:59)
at JiraReportServlet.doPost(JiraReportServlet.java:52)
at JiraReportServlet.doGet(JiraReportServlet.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)

When I manually explored the jar files I found out that.

poi-3.8-20120326.jar contains
org.apache.poi.ss.usermodel->Workbook.class file

and poi-ooxml-3.8-20120326.jar contains
org.apache.poi.ss.usermodel->WorkbookFactory.class file

I have both the jar files included in my class path.

any idea why the exception?

Upvotes: 3

Views: 2606

Answers (3)

abibi abibah
abibi abibah

Reputation: 11

The solution for this is very simple :

  1. download all the jar file in this link http://archive.apache.org/dist/poi/release/bin/poi-bin-3.9-20121203.zip
  2. extract the file and copy all the jar file to "\WebContent\WEB-INF\lib\" in your project. PLEASE NOTE : YOU MUST COPY AND PASTE IT RIGHT INTO YOUR PROJECT IN ECLIPSE, don't copy paste it through windows explorer or place it as external JAR in java build path, because it will never works.

that's it, you're done.. :D Please let me know if this solve your problem..

Upvotes: 0

MozenRath
MozenRath

Reputation: 10040

Just put one of the jars in the WEB-INF\lib of your WAR\EAR because that is where Tomcat Picks the jars from by default.

Just including in eclipse project is not enough when tomcat is not being run though eclipse configuration.

Upvotes: 0

Gagravarr
Gagravarr

Reputation: 48376

org.apache.poi.ss.usermodel.WorkbookFactory is contained with the poi-ooxml jar file. In order to use it, you need the core POI jar, the POI OOXML jar, and their dependencies. The exception you're getting indicates you're missing at least one of those.

You can find out more about the dependencies of the different POI components, both internal and external, on the Apache POI Components page. I'd suggest you review that, review your application and build, then drop in the jars you're missing!

Upvotes: 2

Related Questions