Search code examples
javamavennoclassdeffounderror

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:

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. The problem classes are where they've always been: in JARs referenced in the build path, and there are no compile-time errors.

Some more strange things about this:

  • Switching back to the older non-Maven version doesn't work.
  • 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.
  • Running outside of eclipse using command line DOES work!
  • EDIT: Now I even removed and reinstalled Java - still won't work.

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!


Solution

  • 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. (Probably only the .metadata folder would have sufficed, but I don'thave the nerve to examinate this more deeply.)

    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!