This question is a result of an answer to this question from yesterday
run a java application and a web application in a single maven build within a reactor project<
You can use the jps utility that is bundled inside the JDK to get the process ID of a running Java executable:
The
jps
tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.
Then, when we have retrieved the process ID, we can kill it using taskkill on Windows or kill
or Unix system.
This would be a sample configuration of the maven-antrun-plugin
. It declares the jps
executable and redirect the result of its invocation in the property process.pid
with the AppServer
are kept. jps
output is in the form [PID] [NAME]
so the name is then removed with exec
configuration depending on the OS.
Since you mentioned "gracefully", I used the -15
option on Unix and didn't include the /F
option for Windows. If you want to force the exit, you can use kill -9
on the Unix system and add the /F
option on Windows.