如何停止 Maven 执行

God*_*her 6 maven maven-exec-plugin

我有一个模拟服务器,我需要在运行自动化测试之前在 Jenkins 中启动它,然后在测试运行后停止模拟服务器。

这个模拟服务器是一个 Maven 项目,并且正在使用exec-maven-plugin. 我可以通过运行命令来启动该服务器mvn exec:java。但是我无法通过 Jenkins 停止这个 Maven 项目。我读过相关内容,大多数答案都告诉我们找到这个 Maven 项目的进程 ID,然后杀死它。有没有更干净、更简单的方法来阻止这个项目?

Ess*_*Boy 3

您需要使用Maven 生命周期一部分的目标来启动和停止服务器。

取自此答案的示例

<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>
Run Code Online (Sandbox Code Playgroud)