【问题标题】:How to stop Maven Execution如何停止 Maven 执行
【发布时间】:2018-02-09 00:50:54
【问题描述】:
我有一个模拟服务器,我需要在运行自动化测试之前在 Jenkins 中启动它,然后在我的测试运行后停止模拟服务器。
这个模拟服务器是一个 maven 项目,使用 exec-maven-plugin。我可以通过运行命令mvn exec:java 来启动这个服务器。但是我无法通过 Jenkins 停止这个 Maven 项目。我已经阅读过它,大多数答案都告诉我要找到这个 Maven 项目的进程 ID,然后杀死它。有没有更干净、更简单的方法来停止这个项目?
【问题讨论】:
标签:
maven
maven-exec-plugin
【解决方案1】:
如果你运行的是 linux:
ps aux |grep <project-name> 然后kill -9 <process id>
【解决方案3】:
您需要使用 goals 启动和停止服务器,这是 maven 生命周期的一部分。
取自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>