Tuesday, May 29, 2012

NoClassDefFoundError in Eclipse after upgrade

Sometimes when you open a project for the first time after upgrading your Eclipse IDE, you may find that the project does not run. All the classes and package structure look fine in the Package Explorer but the application fails to run with a NoClassDefFoundError. Even your JUnits fail with the NoClassDefFoundError and the stacktrace usually looks like this:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/vj/test/javatext/TestByteCharConversion  
 Caused by: java.lang.ClassNotFoundException: com.vj.test.javatext.TestByteCharConversion  
  at java.net.URLClassLoader$1.run(URLClassLoader.java:202)  
  at java.security.AccessController.doPrivileged(Native Method)  
  at java.net.URLClassLoader.findClass(URLClassLoader.java:190)  
  at java.lang.ClassLoader.loadClass(ClassLoader.java:307)  
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)  
  at java.lang.ClassLoader.loadClass(ClassLoader.java:248)  
 Could not find the main class: com.vj.test.javatext.TestByteCharConversion. Program will exit.  


The root cause of this could be builders that your project depends upon but are no longer available in the upgraded version of Eclipse. For example, you may have AspectJ code that depends on the AJDT plugin being available in Eclipse. You can confirm this by opening Project -> Properties -> Builders. If you find any "Missing builder" entries, download the appropriate plugins from the Eclipse Marketplace. This should solve your problems. Here is a sample screenshot.


Hope this post helped you. 

No comments: