How to stop Maven Execution

God_Father picture God_Father · Aug 31, 2017 · Viewed 19.6k times · Source

I have a mock server which I need to start in Jenkins before running my Automation tests and then stop the mock server after my tests have run.

This mock server is a maven project and is using exec-maven-plugin. I am able to start this server by running the command mvn exec:java. However I am unable to stop this maven project through Jenkins. I have read about it and most answers tell to find the Process ID of this Maven project and then kill it. Is there a cleaner and easier way to stop this project ?

Answer

Essex Boy picture Essex Boy · Aug 31, 2017

You need to start and stop your sever using goals which are part of the maven life cycle.

An example taken from this answer

<plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
       <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
                <configuration>

                    <fork>true</fork> 
                </configuration>

           </execution>
           <execution>
            <id>tomcat-shutdown</id>
            <goals>
              <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
          </execution>
        </executions>
      </plugin>