Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[m2e-users] NoClassDefFoundError when unit test run via M2E but works fine on command line (the missing class should come from a project with package type 'war')

Hi all,

I get a NoClassDefFoundError if I run a test via M2E. When I run the same test from the command line (via mvn clean install) everything is fine. Is this a M2E bug?

The class that is missing comes from a project with package type 'war'.

This is what I declare in the pom.xml that contains the unit test:

<dependency>
<groupId>com.example.projectM2eTestRuntimeClasspath</groupId>
<artifactId>projectA-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<classifier>classes</classifier>
<scope>test</scope>
</dependency>

This is what I declare in the pom.xml that provides the class:

<artifactId>projectA-war</artifactId>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>


The projects and the unit test that reproduce the problem are attached.

My environment:

Eclipse:
m2e - Maven Integration for Eclipse 1.0.200.20111228-1245 org.eclipse.m2e.feature.feature.group Eclipse.org - m2e Maven Integration for WTP 0.15.2.20120306-2040 org.maven.ide.eclipse.wtp.feature.feature.group JBoss by Red Hat

Maven:
project-m2e-test-runtime-classpath>mvn --version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\java\apache-maven-3.0.3
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: C:\Program Files (x86)\Java\jdk1.6.0_21\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

In Eclipse / Window / Preferences / Maven / Installations the embedded installation is chosen. Switching to the external Maven installation does not make a difference for the unit test.

The entire stacktrace of the error:

java.lang.NoClassDefFoundError: com/example/projectM2eTestRuntimeClasspath/projectA/MyClassA at com.example.projectM2eTestRuntimeClasspath.projectB.MyClassATest.testMyClassA(MyClassATest.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 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)

Attachment: project-m2e-test-runtime-classpath.zip
Description: Binary data


Back to the top