I have a runnable jar that I want to run in a new process before my integration test start (on pre-integration-test
) and get it terminated after my integration tests finish (on post-integration-test
).
One of the things I could use is maven-antrun-plugin or exec-maven-plugin to start new process on pre-integration-test
but how do I terminate it?
Maybe there is a better solution for what I am trying to achieve?
PS: I build my project both on Windows and Linux, so portability matters for me.
You can use maven-process-plugin open sourced by BV to start and stop any process in pre and post-integration phase respectively. There is an example in the readme that does exactly what you want (start a runnable jar). Hope that helps.
The main idea is to write a maven plugin with two goals - start, and stop. Start runs in your pre-integration-phase and runs any process you would like to run. Java's process builder can be used to start processes like running jars, etc. Store the started Process in a datastructure such as a Map or a Stack. 'Stop' will stop all the processes it has started. Since this is such a generic problem, I would recommend the above plugin for starting and stopping any processes easily for your integration tests. Simply add the following plugin:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With