Java NoClassDefFound异常

Java NoClassDefFound异常,java,servlets,apache-poi,Java,Servlets,Apache Poi,我正在使用ApachePOI打开现有的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

我正在使用ApachePOI打开现有的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
}
当我手动浏览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文件


知道为什么会出现异常吗?

org.apache.poi.ss.usermodel.WorkbookFactory
包含在
poioxml
jar文件中。为了使用它,您需要核心POI jar、POI OOXML jar及其依赖项。您得到的异常表明您至少缺少其中一个


您可以在上找到有关不同POI组件(内部和外部)依赖关系的更多信息。我建议你检查一下,检查一下你的应用程序和构建,然后扔掉你丢失的罐子

只需将其中一个JAR放入WAR\EAR的
WEB-INF\lib
,因为默认情况下Tomcat从中选择JAR


当tomcat没有通过eclipse配置运行时,仅仅包含在eclipse项目中是不够的。

解决方案非常简单:

  • 下载此链接中的所有jar文件
  • 提取文件并将所有jar文件复制到项目中的“\WebContent\WEB-INF\lib\”中。请注意:您必须将它复制并粘贴到ECLIPSE中的项目中,不要通过windows资源管理器复制粘贴它,也不要将它作为外部JAR放在java构建路径中,因为它永远不会工作
  • 就这样,你完成了D
    请让我知道这是否解决了您的问题。

    似乎您错误地将它们放在您的类路径中,它们必须放在您的tomcat类路径中,而不仅仅是eclipse类路径中。建议手动将其中一个JAR放入WEB-INF/lib。关于如何调试类加载,请参见“关于如何调试类加载的说明”。@MozenRath:我认为您的回答是正确的,这样我就可以接受它,并使用maven或gradle的ivy或其他管理依赖关系的构建工具。ApachePOI在maven Central中以及所有依赖关系中完全可用。从长远来看,切换到maven/ivy/gradle是明智的,但可能不是解决这一问题的先决条件!我包含了两个jar文件。问题中提到了不,你认为你已经包括了罐子,但你显然没有因此而产生错误。。。您需要确保JAR(及其依赖项!)在编译和运行时都可用code@Gagravarr:k现在我确信我已经包含了这两个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