Discuss / Java / NoClassDefFoundError错误

NoClassDefFoundError错误

Topic source

我在运行main()方法时,出现

错误: 无法初始化主类 Main

原因: java.lang.NoClassDefFoundError: org/apache/catalina/WebResourceRoot

麻烦大家看看什么原因?

何小狗____

#2 Created at ... [Delete] [Delete and Lock User]

仁兄你解决没有啊,我也遇到了这种情况,不知怎么解决。

何小狗____

#3 Created at ... [Delete] [Delete and Lock User]

仁兄问题我已经解决了!!

1,问题产生的原因:廖大佬用的eclipse,我们用的IDEA,我们在IDEA中,maven配置<scope>provided</scope>,就告诉了IDEA程序会在运行的时候提供这个依赖,但是实际上却并没有提供这个依赖。

2,解决方法:

去掉<scope>provided</scope>,改<scope>complie</scope>,然后reimport就可以了。

廖雪峰

#4 Created at ... [Delete] [Delete and Lock User]

那是idea的问题,如果你把provided改成compile,生成的war包会很大,因为把tomcat打包进去了

解决方案

打开idea的Run/Debug Configurations:

选择Application - Main

右侧Configuration:Use classpath of module

钩上☑︎Include dependencies with "Provided" scope

何小狗____

#5 Created at ... [Delete] [Delete and Lock User]

谢谢廖大佬的回复

木火应

#6 Created at ... [Delete] [Delete and Lock User]

我在命令行下搞了很久都没试出来,幸好看到各位的回复,否则这一天时间可能就静悄悄的溜走了😂

木火应

#7 Created at ... [Delete] [Delete and Lock User]

不过真要在命令行操作,可以把war改成jar,且provided改成compile,并导入maven-shade-plugin依赖,执行mvn clean package 后运行jar包即可

之前没会弄,这里回来作下说明😁


  • 1

Reply