title: Spring Boot Maven Integration Test Giving ClassNotFoundException
body: <p>I have a spring boot project with two apps, one in src/test and one in src/main. I have two apps, one mediator to connect with a SOAP endpoint and one acting as a mock server for testing. </p>
  
  <p>I have an integration test checking if it will hit ( requires test app(port 9119) and main app(port 28433) to be up) </p>
  
  <p>I used maven spring boot plugin to configure to run both apps like this in my POM and also made it skip unit test when running mvn verify. </p>
  
  <pre><code>&lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
               &lt;includePom&gt;true&lt;/includePom&gt;          
          &lt;/configuration&gt;  
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;pre-integration-test&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;start&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                 &lt;mainClass&gt;com.nulogix.billing.App&lt;/mainClass&gt;   
                      &lt;/configuration&gt; 
  
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;pre-integration-test2&lt;/id&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;start&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                 &lt;mainClass&gt;com.nulogix.billing.mockserver.MockServerApp&lt;/mainClass&gt;   
                      &lt;/configuration&gt; 
  
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;post-integration-test&lt;/id&gt;
                      &lt;goals&gt;
  
                           &lt;goal&gt;stop&lt;/goal&gt;                  
                      &lt;/goals&gt;
                       &lt;configuration&gt;
                 &lt;mainClass&gt;com.nulogix.billing.App&lt;/mainClass&gt;   
                      &lt;/configuration&gt;
  
                  &lt;/execution&gt;
                  &lt;execution&gt;
                      &lt;id&gt;post-integration-test2&lt;/id&gt;
                      &lt;goals&gt;
  
                           &lt;goal&gt;stop&lt;/goal&gt;                  
                      &lt;/goals&gt;
                       &lt;configuration&gt;
                 &lt;mainClass&gt;com.nulogix.billing.mockserver.MockServerApp&lt;/mainClass&gt;   
                      &lt;/configuration&gt;
  
                  &lt;/execution&gt;
              &lt;/executions&gt;
  
          &lt;/plugin&gt;
  
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.18.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;integration-test&lt;/goal&gt;
                          &lt;goal&gt;verify&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&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;3.0.0-M3&lt;/version&gt;
      &lt;configuration&gt;
          &lt;skipTests&gt;true&lt;/skipTests&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>When I run mvn verify it loads 28433 in pre-integration phase but when it try to run 9119 in pre-integration phase 2 it gives this error:</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.nulogix.billing.mockserver.MockServerApp
      at java.net.URLClassLoader.findClass (URLClassLoader.java:436)
      at java.lang.ClassLoader.loadClass (ClassLoader.java:588)
      at java.lang.ClassLoader.loadClass (ClassLoader.java:521)
      at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:553)
      at java.lang.Thread.run (Thread.java:835)
  </code></pre>
  
  <p>The class path directory is right. I tried adding a class scope in my pom to it but it didn't seem to fix the issue and gave me the same error. </p>
  
  <p>In the post-integration phase when it shuts down it gives this error which I assume just means it couldn't load the application context hence there is no bean found to shut it down </p>
  
  <pre><code>Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.0.RELEASE:stop (post-integration-test2) on project billing_mediator: Spring application lifecycle JMX bean not found (fork is null). Could not stop application gracefully: org.springframework.boot:type=Admin,name=SpringApplication -&gt; [Help 1]
  </code></pre>
  
  <p>When I run mvn -x for stack trace it automatically gives me a build failure and gives me this </p>
  
  <pre><code>org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format &lt;plugin-prefix&gt;:&lt;goal&gt; or &lt;plugin-group-id&gt;:&lt;plugin-artifact-id&gt;[:&lt;plugin-version&gt;]:&lt;goal&gt;. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
  </code></pre>
  
  <p>Is this implying I have my POM setup wrong?</p>