I have scenario, where I need to kill a java process.
Here is my scenario:
I have web application in that web application I have implemented a Listener
class like below
public class MyListener extends ServletContextListener {
java.lang.Process ps = null;
public void contextInitialized(ServletContextEvent arg0) {
// This will be excuted when my web application executed
String command= "cmd.exe start maybatch";// This command is to execute a batch program that triggers java program
ps = Runtime.getRunTime().exec(command);
}
public void contextDestroyed(ServletContextEvent arg0) {
//This part will be executed when server shutdown happens.
// Here I want to close the java process which was triggered when project deployed.
if( ps !=null)
ps.destroy();
}
}
}
What my requirement is to close the Java process when my tomcat is shutting down and start the java program when my web application deployed.
Everything is working fine till to start the java process when Project is deployed.
But I dont know how to close the java process which was triggered when project is deployed
Any help would be appreciated. Thanks in advance.
Sorry to be not clear..
mybatch
lanches a new java program
.