If I start a forked java process from an ant script and kill the ant process, it does not kill the java process. This is the case whether running it from the IDE or from the command line.
<target name="myTarget" >
<java classname="path.to.MyClass"
fork="yes"
failonerror="true"
maxmemory="128M">
<classpath refid="run" />
</java>
</target>
Is there a way to link these, so that killing the ant process will kill the java process?
I've seen the following Q&A - but this seems to focus on how to kill the java process manually. I don't want to do this, because I have a number of other java applications running, and finding the right java.exe process to kill in TaskManager is not always straight forward.
Unfortunately, it appears that this is a long-standing and known issue.
When the Ant task is terminated, the forked Java process shutdown hooks are not fired. (This seems to have been an issue since Java 1.4 (!))
For reference:
If you set fork to "no", the same VM will be used, so killing the ant process will kill this specific java process too.
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