Thursday, April 14, 2011

m2eclipse plugin: NoClassDefFoundError when running JUnit tests

We are using the m2eclipse plugin (including its WTP extension) for leveraging Maven integration in Eclipse. Recently, we ran into the issue of class not found errors, when trying to run JUnit tests from Eclipse (Run/Debug as JUnit test). More information about this problem can be found here, here or here.
A workaround has been suggested to change the build path order in Eclipse - i.e., moving the Maven Dependencies before the JRE System Library in the build order. However, this did not solve our problem.

We discovered that the auto-clean feature of the maven-clean-plugin caused the troubles in our setting, which we used as follows in the pom:


<plugin>    
  <artifactId>maven-clean-plugin</artifactId>    
  <version>2.4</version>    
  <executions>      
    <execution>           
      <id>auto-clean</id>        
      <phase>initialize</phase>        
      <goals>          
        <goal>clean</goal>        
      </goals>      
    </execution>    
  </executions>  
</plugin>

After removing the maven-clean-plugin from our pom.xml, running JUnit tests from a m2eclipse project worked like a charm.

No comments:

Post a Comment