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
.. on the JUnit Test case! :-) yuck.This was the stacktrace in it's entirety
Class not found
at Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
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.


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.

No comments:

Current 5 booksmarks @