Saturday 12 September 2009

Eclipse Galileo java.lang.ClassNotFoundException with JUnit Tests

This post describes my problem, and the solution
Recently I upgraded to Eclipse Galileo 3.5 on my Ubuntu dev box. All was well and I noticed no degradation or changes (new, good or bad) .. until ..
Until I went to run my first testcase in my new ete library. I received the beautiful
java.lang.ClassNotFoundException
.. on the JUnit Test case! :-) yuck.This was the stacktrace in it's entirety
Class not found org.soqqo.ete.source.data.EhCachedDataRowListTest
java.lang.ClassNotFoundException: org.soqqo.ete.source.data.EhCachedDataRowListTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
It really threw me because on the command line, Maven2 (mvn test) test cases still worked fine. So I knew I havd an Eclipse problem. The upgrade was my key, ie: it was within 20 minutes of starting Galileo that this error occured.

So I ran my test cases in Eclipse 3.4 and it worked. 3.5 I say.. but then, that was too simple. There must be something up.

Much googling around for a good few hours each day and I found nothing. It then struck me that it was NOT eclipse, but rather a plugin I had in Eclipse. As it turned out it was the opposite of that: In that I did NOT have a plugin.

In the project, in the Maven 2 POM I declare some extra eclipse settings, to use the aspectJ Eclipse nature and also something for Spring as part of the Spring IDE. When you run
mvn eclipse:eclipse
the .classpath and .project files generated have all you relevate bits in there for eclipse.
I had this in the POM.


  maven-eclipse-plugin
  
    
       org.eclipse.ajdt.ui.ajnature 
       org.eclipse.jdt.core.javanature 
       org.springframework.ide.eclipse.core.springnature 
    
    
       org.eclipse.ajdt.core.ajbuilder 
       org.springframework.ide.eclipse.core.springbuilder 
    
    
      org.eclipse.jdt.launching.JRE_CONTAINER
      org.eclipse.ajdt.core.ASPECTJRT_CONTAINER
    
  

My guess was that I did not have the AspectJ plugin and the Spring Builder plugins, so the build paths were all screwey, which meant that Eclipse classpaths for JUnit were failing.

I was right, a quick uncomment of the whole extra customisation on the eclipse maven plugin in the pom.xml, and rerun mvn eclipse:eclipse and I was up and running again.

cheers. Hope this finds someone else a short path back to productivity.

Current 5 booksmarks @ del.icio.us/pefdus