I would like to be able to start and stop Tomcat from a Java program running on a Windows machine. I looked at the contents of startup.bat, shutdown.bat and catalina.bat, and it looks like one easy way to do that would be to set system properties that correspond to the -D command line arguments as they are set up in the script files, and then call Bootstrap.main with a list argument that contains either "start" or "stop". When I tried this running my Java program in Eclipse, the call to Bootstrap.main(new String[]{"start"}) did not return. I don't understand why this is, because running startup.bat in a command prompt window gets Tomcat running and then returns to a command prompt. Is there a way to call Bootstrap.main(new String[]{"start"}) in an application's main thread so that it returns and Tomcat continues running?
I also tried calling Bootstrap.main(new String[]{"start"}) in a separate thread, but I must not have done it right, because when I call Bootstrap.main(new String[]{"stop"}) it claims to stop Tomcat but there is still a process listening on the port that I designated. What is the best way to start and stop Tomcat programmatically from a Java application? If it is better to do it using a different class, such as Tomcat or Embedded, could someone point me to information about how to do that? I tried using the Tomcat class recently and I couldn't get it to work either. I am working with Tomcat 7.0.25 x64 on Windows 2008 Server. Thanks, Mike