我有一个可运行的 jar,我想在集成测试开始之前在新进程中运行(在pre-integration-test
)并在我的集成测试完成后终止它(在post-integration-test
).
我可以使用的东西之一是maven-antrun-插件 https://maven.apache.org/plugins/maven-antrun-plugin/ or 执行 maven 插件 http://mojo.codehaus.org/exec-maven-plugin/usage.html开始新流程pre-integration-test
但我该如何终止它呢?
也许对于我想要实现的目标有更好的解决方案?
PS:我在 Windows 和 Linux 上构建我的项目,因此可移植性对我来说很重要。
您可以使用maven-进程-插件 https://github.com/bazaarvoice/maven-process-plugin由 BV 开源,可分别在集成前和集成后阶段启动和停止任何流程。自述文件中有一个示例可以完全满足您的需求(启动一个可运行的 jar)。希望有帮助。
主要思想是编写一个具有两个目标的 Maven 插件 - 启动和停止。 Start 在预集成阶段运行并运行您想要运行的任何进程。 Java的进程构建器可用于启动进程,例如运行jar等。将启动的进程存储在数据结构中,例如Map或Stack。 “停止”将停止它启动的所有进程。由于这是一个普遍问题,我建议使用上述插件来轻松启动和停止集成测试的任何进程。只需添加以下插件:
<plugin>
<groupId>com.bazaarvoice.maven.plugins</groupId>
<artifactId>process-exec-maven-plugin</artifactId>
<version>0.4</version>
<executions>
<!--Start process-->
<execution>
<id>start-jar</id>
<phase>pre-integration-test</phase>
<goals><goal>start</goal></goals>
<configuration>
<workingDir>app</workingDir>
<arguments>
<argument>java</argument>
<argument>-jar</argument>
<argument>app.jar</argument>
</arguments>
</configuration>
</execution>
<!--Stop Process-->
<execution>
<id>stop-jar-process</id>
<phase>post-integration-test</phase>
<goals><goal>stop-all</goal></goals>
</execution>
</executions>
</plugin>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)