我正在使用 apache poi 打开现有的 excel 文件。
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
}
我有一个 servlet,它从 html 页面获取日期并调用generateReport()
. 问题是该程序以前以相同的tomcat 6
版本和servlet2.4
版本运行。在 Eclipse 中,该行没有编译时错误WorkbookFactory.create()
。这是堆栈跟踪。
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)
当我手动浏览 jar 文件时,我发现了这一点。
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
我的类路径中包含两个 jar 文件。
知道为什么例外吗?