java.lang.ClassNotFoundException:org.apache.poi.ss.usermodel.Workbook

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java.lang.ClassNotFoundException:org.apache.poi.ss.usermodel.Workbook相关的知识,希望对你有一定的参考价值。

我正在尝试访问Apache Workbook模块的excel文件。代码有时运行得很好,但大多数时候我得到一个错误说:

例外

javax.servlet.ServletException:Servlet执行引发异常org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

java.lang.NoClassDefFoundError:org / apache / poi / ss / usermodel / Workbook

根本原因

java.lang.ClassNotFoundException:org.apache.poi.ss.usermodel.Workbook

我查了一下,看到这是一个jar文件问题。试图从我身边修复它,但我仍然得到同样的错误。

这是我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>XYZ</groupId>
    <artifactId>ABC</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>ScriptsGenerator Maven Webapp</name>
    <url>http://maven.apache.org</url>
  <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
      <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.15</version>
      </dependency>
    <dependency>
        <groupId>org.lucee</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.15.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
            <version>3.15</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
            <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.5.8</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.6.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
    <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
    <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-collections4</artifactId>
       <version>4.1</version>
    </dependency>
    <dependency>
  <groupId>commons-fileupload</groupId>
  <artifactId>commons-fileupload</artifactId>
  <version>1.2</version>
  </dependency>

    </dependencies>
    <build>
      <finalName>AAAA</finalName>
    </build>
  </project>

我哪里错了?

答案

请检查apache poi jar是否已下载,

还可以尝试使用以下依赖关系poi-ooxml-schemas

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.15</version>
</dependency>
另一答案

看起来你在servlet容器中运行它,这可能意味着容器有自己的jar文件集。例如,Tomcat将位于Tomcat / lib目录中。检查servlet容器正在使用哪些jar,以查看其中一个是否与您正在使用的jar不兼容。

您正在寻找的是旧版本的poi,它没有您需要的课程。如果这样的jar存在并且在正确的jar之前加载,它可能会导致您看到的问题,即使您的Web应用程序本身具有正确的版本。

另一答案

清理项目,删除{User_Directory} /。m2文件夹的内容并重新运行项目

在Windows系统下,您可以找到maven repo路径为C: Users {user_name} 。m2

在linux系统下,你可以找到maven repo路径为/home/{user_name}/.m2

以上是关于java.lang.ClassNotFoundException:org.apache.poi.ss.usermodel.Workbook的主要内容,如果未能解决你的问题,请参考以下文章