1

I've been following a PluralSight course on JavaEE using eclipse and maven. I'm currently trying to write some tests, but when running mvn package from the cmd line I've been getting this error:

Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process

Sometimes it refers to:

java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener

and sometimes:

java.lang.NoClassDefFoundError: org/junit/runner/Description

I've done a bit of reading around and RunListener seems to have been introduced in JUnit 4.0. But as far as I can tell I have the correct dependency - JUnit 4.12 is in my dependency hierarchy. And I've now changed all my files to the Exercise files in order to trouble shoot this.

I'm guessing that maybe I've fundamentally misunderstood how maven and dependencies work, RE jars and the classpath, and that I still need to point eclipse or the cmd line to the JUnit jar? (I get the same errors in both). I just find that odd given that other JUnit classes are recognised in my java objects. Here's my (pluralsight's) pom anyway:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.pluralsight.javaee-getting-started.javaee-getting-started-m6</groupId>
        <artifactId>bookstore-back</artifactId>
        <version>1.0</version>
        <packaging>war</packaging>
        <name>Getting Started :: javaee-getting-started-m6 :: Testing the Repository :: Back</name>

        <properties>
            <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <!-- Test -->
            <version.junit>4.12</version.junit>
            <version.arquillian>1.1.13.5</version.arquillian>
            <version.arquillian.wildfly>2.0.2.Final</version.arquillian.wildfly>
            <version.shrinkwrap>1.2.6</version.shrinkwrap>
            <!-- Plugins -->
            <version.surefire.plugin>2.19.1</version.surefire.plugin>
        </properties>

        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.arquillian</groupId>
                    <artifactId>arquillian-universe</artifactId>
                    <version>${version.arquillian}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>

        <dependencies>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>

            <!-- TEST -->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${version.junit}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.arquillian.universe</groupId>
                <artifactId>arquillian-junit</artifactId>
                <scope>test</scope>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>org.jboss.shrinkwrap</groupId>
                <artifactId>shrinkwrap-api</artifactId>
                <version>${version.shrinkwrap}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.wildfly.arquillian</groupId>
                <artifactId>wildfly-arquillian-container-remote</artifactId>
                <version>${version.arquillian.wildfly}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>

        <build>
            <finalName>bookstore-back</finalName>

            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${version.surefire.plugin}</version>
                    <configuration>
                        <systemPropertyVariables>
                            <arquillian.launch>arquillian-wildfly-remote</arquillian.launch>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.6</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>7.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>src</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    </project>

Am I on the right track with the classpath idea?

NickW
  • 1,207
  • 1
  • 12
  • 52
  • 1
    First try deleting your `.m2` folder where Maven stores it's dependencies and doing another build. Sometimes jar files get corrupted (ex. Junit jar file might be corrupted, which could explain why it does not find classes). Also run `mvn dependency-tree` to check if you indeed have the correct versions (though should be fine based on your pom). Also all of your tests are under `src/test/java` right? – helospark Dec 06 '17 at 17:49
  • Deleted my .m2 file and repackaged - I think you solved this problem - which has flagged up an older one. But thanks though! I now get the runtime exception `could not connect to http-remoting://127.0.0.1:9990`. Which while annoying, is at least the error I get while trying to run `jboss-cli.bat --connect --controller=localhost:9990`. I had previously been having problems starting WildFly with this command (standalone.bat however works fine.) – NickW Dec 06 '17 at 18:10
  • running `mvn dependency:tree` results in: `Execution default-cli of goal org.apache.maven.plugins:maven-dependency-plugin:2.6:tree failed: A required class was missing while executing org.apache.maven.plugins:maven-dependency-plugin:2.6:tree: org/sonatype/aether/graph/DependencyNode` – NickW Dec 06 '17 at 18:12
  • `org/sonatype/aether/graph/DependencyNode` this is caused by a very old maven-dependency-plugin. You need at least version 2.8. See: https://stackoverflow.com/questions/18169415/java-lang-classnotfoundexception-org-sonatype-aether-version-invalidversionspec Regarding WildFly, I'm not familiar with it, I suggest to ask another question. – helospark Dec 07 '17 at 18:46
  • Also posted an answer based on our conversation. – helospark Dec 07 '17 at 18:46

1 Answers1

1

Delete your .m2 folder where Maven stores it's dependencies and do another build. Sometimes jar files get corrupted (ex. Junit jar file might be corrupted, which could explain why it does not find classes).

helospark
  • 1,420
  • 9
  • 12
  • 2
    while you are guessing, why not recommend formatting the hard drive, reinstalling OS and everything else as well, or you do not have a complete *answer*. –  Dec 07 '17 at 18:48
  • Please read [How do I write a good answer?](http://stackoverflow.com/help/how-to-answer) before attempting to answer more questions. –  Dec 07 '17 at 18:49
  • @JarrodRoberson My answer is based on the conversation I had with the OP in the comment section of this question. It solved the OP's problem. Is it better to leave the question unanswered? – helospark Dec 07 '17 at 18:53
  • Rephrased the answer. – helospark Dec 07 '17 at 18:56