Java.lang.NoClassDefFoundError : org/apache/poi/ss/usermodel/Font

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23568253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 00:00:55  来源:igfitidea点击:

Java.lang.NoClassDefFoundError : org/apache/poi/ss/usermodel/Font

javaexcelspring-mvcruntime-errorapache-poi

提问by TheByeByeMan

I'm Using Apache POIto read some Excel files. I've created a console application to do the job, after that I've tried to integrate the code in a Spring MVCwebApp (nothing special, I know). I've included the same Jar files to my Classpath, but whenever I try to run the code, I got this error:

我正在使用Apache POI读取一些 Excel 文件。我创建了一个控制台应用程序来完成这项工作,之后我尝试将代码集成到Spring MVCwebApp 中(没什么特别的,我知道)。我在Classpath 中包含了相同的 Jar 文件,但是每当我尝试运行代码时,我都会收到此错误:

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

I believe that the class Font was found during compilation time, but not at runtime. I'm pretty sure that the problem is not with the ClassPath, but I can't figure out how to solve this.

我相信 Font 类是在编译时找到的,但不是在运行时找到的。我很确定问题不在于ClassPath,但我不知道如何解决这个问题。

EDIT : When I copy the same code in a new class with main method (in the same web project), and run my web app as a console java app, it works.

编辑:当我使用 main 方法(在同一个 web 项目中)在一个新类中复制相同的代码,并将我的 web 应用程序作为控制台 java 应用程序运行时,它可以工作。

采纳答案by Guen_hamza

To solve this issue do the following :

要解决此问题,请执行以下操作:

1 - check if your Pom.xml doesn't contain any of the Apache POI dependencies.

1 - 检查您的 Pom.xml 是否不包含任何 Apache POI 依赖项。

2 - delete poi folder from your Maven repository.

2 - 从您的 Maven 存储库中删除 poi 文件夹。

3 - run your project as a maven clean

3 - 将您的项目作为 maven clean 运行

4 - update project

4 - 更新项目

5 - Import again you poi Jars to your classpath

5 - 再次将你的 poi Jars 导入你的类路径

6 - run and enjoy

6 - 运行并享受