You can call a MS-DOS command in Java environment. For exampe, if I
stop "Symantec Core LC" service in my computer. My testing code is like
following.
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
*
* @author Carl Wu
*
*/
public class StopServiceTest {
/**
* Test main method
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StopServiceTest test = new StopServiceTest();
test.stopService("\"Symantec Core LC\"");
}
/**
* Stop a service in Windows XP
*
* @param serviceName the service name
* If there is space in service name string, please add "\" before and
after of the service name.
*/
protected void stopService(String serviceName) {
try {
String command = "net stop " + serviceName;
//print command name
System.out.println(command);
Process p = Runtime.getRuntime().exec(command);
//print execute results
InputStream is = p.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
is.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
The testing results are:
net stop "Symantec Core LC"
The Symantec Core LC service is stopping.
The Symantec Core LC service was stopped successfully.
May it helpful to you,
Carl Wu
> I need to restart the tomcat service, from within my application
> whenever there is a configuration change. Because i'm loading some
[quoted text clipped - 6 lines]
> this in my java program
> Appreciate your input
vanisathish@gmail.com - 15 Nov 2006 00:43 GMT
Thanks for the update. But if i stop the Tomcat Service, how will start
again, since the tomcat is not there already. I'm using this approach
to start/stop other services in the way you've mentioned
Thanks
> You can call a MS-DOS command in Java environment. For exampe, if I
> stop "Symantec Core LC" service in my computer. My testing code is like
[quoted text clipped - 73 lines]
> > this in my java program
> > Appreciate your input
Arne Vajhøj - 15 Nov 2006 02:16 GMT
> Thanks for the update. But if i stop the Tomcat Service, how will start
> again, since the tomcat is not there already. I'm using this approach
> to start/stop other services in the way you've mentioned
You can obviously not stop and start Tomcat directly from
code running inside Tomcat.
I can see two roads forwards for you:
1) restart the web app and not the server
2) start an independent process that stop and start the service
Arne