title: Junit maven build error (maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process)
body: <p>I created a sample struts 2 project &amp; J-unit test case by referring the  <a href="http://self-learning-java-tutorial.blogspot.com.au/2015/04/struts2-junit-integration.html" rel="nofollow noreferrer">link</a>.</p>
  
  <p><strong>Below is my POM file.</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;au.com.woolworths&lt;/groupId&gt;
    &lt;artifactId&gt;struts_junit&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;name&gt;struts_junit Maven Webapp&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
    &lt;dependencies&gt;
      &lt;!-- https://mvnrepository.com/artifact/junit/junit --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;3.8.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
         &lt;groupId&gt;org.apache.struts&lt;/groupId&gt;
         &lt;artifactId&gt;struts2-core&lt;/artifactId&gt;
         &lt;version&gt;2.3.4&lt;/version&gt;
        &lt;/dependency&gt;
       &lt;dependency&gt;
         &lt;groupId&gt;org.apache.struts&lt;/groupId&gt;
         &lt;artifactId&gt;struts2-junit-plugin&lt;/artifactId&gt;
         &lt;version&gt;2.3.4&lt;/version&gt;
        &lt;/dependency&gt;
       &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
          &lt;version&gt;3.0.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;finalName&gt;struts_junit&lt;/finalName&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.5.1&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.6&lt;/source&gt;
            &lt;target&gt;1.6&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.0.0&lt;/version&gt;
          &lt;configuration&gt;
            &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
          &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
          &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;configuration&gt;
          &lt;lifecycleMappingMetadata&gt;
               &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                      &lt;pluginExecutionFilter&gt;
                          &lt;groupId&gt;
                              org.apache.maven.plugins
                          &lt;/groupId&gt;
                          &lt;artifactId&gt;
                              maven-toolchains-plugin
                          &lt;/artifactId&gt;
                          &lt;versionRange&gt;
                              [1.1,)
                          &lt;/versionRange&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;toolchain&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/pluginExecutionFilter&gt;
                      &lt;action&gt;
                          &lt;ignore&gt;&lt;/ignore&gt;
                      &lt;/action&gt;
                  &lt;/pluginExecution&gt;
              &lt;/pluginExecutions&gt;
            &lt;/lifecycleMappingMetadata&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
        &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.19.1&lt;/version&gt;
              &lt;dependencies&gt;
                &lt;dependency&gt;
                  &lt;groupId&gt;org.apache.maven.surefire&lt;/groupId&gt;
                  &lt;artifactId&gt;surefire-junit47&lt;/artifactId&gt;
                  &lt;version&gt;2.19.1&lt;/version&gt;
                &lt;/dependency&gt;
                &lt;dependency&gt;
                  &lt;groupId&gt;org.hamcrest&lt;/groupId&gt;
                  &lt;artifactId&gt;hamcrest-all&lt;/artifactId&gt;
                  &lt;version&gt;1.3&lt;/version&gt;
                &lt;/dependency&gt;
              &lt;/dependencies&gt;
              &lt;configuration&gt;
                &lt;parallel&gt;methods&lt;/parallel&gt;
                &lt;threadCount&gt;10&lt;/threadCount&gt;
                &lt;useSystemClassLoader&gt;false&lt;/useSystemClassLoader&gt;
              &lt;/configuration&gt;
           &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>I am able to execute the test-case successfully in eclipse, but during maven build, I am getting the below error.</p>
  
  <pre><code>-------------------------------------------------------
   T E S T S
  -------------------------------------------------------
  
  Results :
  
  Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
  
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time: 12.768 s
  [INFO] Finished at: 2017-02-03T11:22:46+11:00
  [INFO] Final Memory: 11M/168M
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project struts_junit: Execution default-test of goal org.apach
  e.maven.plugins:maven-surefire-plugin:2.19.1:test failed: There was an error in the forked process
  [ERROR] java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
  [ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
  [ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
  [ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  [ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
  [ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
  [ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
  [ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
  [ERROR] at java.security.AccessController.doPrivileged(Native Method)
  [ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  [ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  [ERROR] at java.lang.Class.getDeclaredConstructors0(Native Method)
  [ERROR] at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
  [ERROR] at java.lang.Class.getConstructor0(Class.java:3075)
  [ERROR] at java.lang.Class.getConstructor(Class.java:1825)
  [ERROR] at org.apache.maven.surefire.util.ReflectionUtils.getConstructor(ReflectionUtils.java:79)
  [ERROR] at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:130)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.createProviderInCurrentClassloader(ForkedBooter.java:321)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
  [ERROR] Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
  [ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  [ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  [ERROR] ... 22 more
  [ERROR] -&gt; [Help 1]
  [ERROR]
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR]
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
  </code></pre>
  
  <p>Can someone advice me why this error occurs and how to resolve this issue ?</p>