简体   繁体   English

在 Eclipse 中突然出现 NoClassDefFoundError(并且只有在那里)

[英]Suddenly NoClassDefFoundError in Eclipse (and only there)

After having converted my project (just plain Java 1.8, nothing special) in eclipse (Mars.2) to Maven (Right-click on project => Configure => Maven project), suddenly I can't run the usual classes that always worked before, getting this message:在 eclipse (Mars.2) 中将我的项目(只是普通的 Java 1.8,没什么特别的)转换为 Maven(右键单击项目 => 配置 => Maven 项目)后,突然间我无法运行通常有效的类之前,收到此消息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils
    at eas.veryFastPDF.script.RepresentableDefault.<init>(RepresentableDefault.java:169)
    at eas.veryFastPDF.script.RepresentableDefault$1.<init>(RepresentableDefault.java:1336)
    at eas.veryFastPDF.script.RepresentableDefault.<clinit>(RepresentableDefault.java:1336)
    at eas.veryFastPDF.HelpTexts.<clinit>(HelpTexts.java:525)
    at eas.GlobalVariables.<clinit>(GlobalVariables.java:52)
    at eas.plugins.PluginFactory.deserializePlugins(PluginFactory.java:220)
    at eas.plugins.PluginFactory.loadPluginsFromFile(PluginFactory.java:127)
    at eas.plugins.PluginFactory.<clinit>(PluginFactory.java:118)
    at eas.startSetup.ParCollection.complete(ParCollection.java:1304)
    at eas.startSetup.Starter.main(Starter.java:1924)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 10 more

If I comment out the parts that require StringUtils, other referenced libraries cause the same error.如果我注释掉需要 StringUtils 的部分,其他引用的库会导致相同的错误。 The problem classes are where they've always been: in JARs referenced in the build path, and there are no compile-time errors.问题类一直存在:在构建路径中引用的 JAR 中,并且没有编译时错误。

Some more strange things about this:关于这个的一些更奇怪的事情:

  • Switching back to the older non-Maven version doesn't work.切换回旧的非 Maven 版本不起作用。
  • Project cleanup doesn't work.项目清理不起作用。
  • Clean new checkout of the project doesn't work.清理新的项目结帐不起作用。
  • Even installing a new Eclipse version (Neon.2 - was due anyway) doesn't work.即使安装新的 Eclipse 版本(Neon.2 - 无论如何都该到期)也不起作用。
  • Running outside of eclipse using command line DOES work!使用命令行在 eclipse 之外运行确实有效!
  • EDIT: Now I even removed and reinstalled Java - still won't work.编辑:现在我什至删除并重新安装了 Java - 仍然无法正常工作。

What the hell is happening??这到底是怎么回事??

EDIT: I obviously checked all the answers from the suggested "duplicate" question, and they won't work.编辑:我显然检查了建议的“重复”问题中的所有答案,但它们不起作用。 Please don't mark as duplicate - it's not!请不要标记为重复 - 不是!

This is what finally (after several hours) worked for me:这就是最终(几个小时后)对我有用的:

I removed all the stuff eclipse stored in the workspace folder - more precisely, basically every folder starting with a dot.我删除了存储在工作区文件夹中的所有东西 eclipse - 更准确地说,基本上每个文件夹都以一个点开头。 (Probably only the .metadata folder would have sufficed, but I don'thave the nerve to examinate this more deeply.) (可能只有 .metadata 文件夹就足够了,但我没有勇气更深入地研究这个。)

Apparently, something about the classpath is stored permanently in the workspace, so switching back to an earlier version didn't solve my problem.显然,有关类路径的某些内容永久存储在工作区中,因此切换回早期版本并没有解决我的问题。

Just a warning: This solution did work, but cleaning up the workspace like this will let eclipse forget virtually everything!只是一个警告:这个解决方案确实有效,但是像这样清理工作区会让 eclipse 忘记几乎所有的事情!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM