How to stop a running tomcat with a java program?
<p>I am writing an update program which requires the running tomcat to be stopped. I tried it with calling the net stop SERVICENAME from java but it does not work. It returns error code 2 and aborts, I guess that it's because of security reasons. Does someone know how I can solve this. Can I define that the java program runs as administrator and has therefore the necessary rights, or is there another way?</p>

<p>Here is my code:</p>

<pre><code>String command = "cmd.exe /C net stop myservice";
Process p;
p = Runtime.getRuntime().exec(command);
p.waitFor();
log.info("exit value  was "    +p.exitValue());
</code></pre>
