Killing Java Process from Ant in Windows
I wanted to write a ant script for one of the environment, which would perform following tasks in order which will be repeated
- Take Latest Code
- Compile
- Create WAR
- Undeploy currently installed WAR from tomcat
- Stop the tomcat
- Copy the WAR to tomcat webapps folder
- Start the tomcat Starting the tomcat -
1
Stopping the tomcat - I was facing some issues using the tomcat shutdown.bat as tomcat server was not stopping due to one of the application deployed was not getting stopped gracefully. And the next time tomcat tried to start it used to give “JVM_BIND Exception -Port already in use”. As Windows doesn’t have a native kill command, I have used following which allowed me to kill any java process using ant.PsKill - Running PsKill with a process ID directs it to kill the process of that ID on the local computer.jps - The jps command will report the process ID of each JVM running on local computer.
1
2
Killing tomcat instance with PID - "${pid.out}"
The above way can be used to kill any java process using the ant.