I've got a strage problem.
When I build my maven project like this:
mvn clean package
it compiles and successfully runs the unit tests but when I do
mvn clean install
it still compiles, reports build success but shows this strange error:
java.lang.NoClassDefFoundError: com/foo/BarClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at com.foo.BarTest.shouldTestSomething(BarTest.java:35)
I've got maven 3.0.4, surefire-plugin-version 2.14, junit 4.11
Here are representative parts of my pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
</plugin>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
I've played with changing surefire/junit versions as well with surefire's <useSystemClassLoader>false</useSystemClassLoader>
but still got the problem.
I really don't understand the cause of the NoClassDefFound
error ...
Can you please help me?
So finally I fixed the messy problem:
I also had cobertura
plugin running (like any quality software project has :), that instrumented the classes thus triggering a recompile, thus a re-run of unit-tests hence the strange NoClassDefError
Huh, what a busy day!