What is the best way to start/stop/restart Apache Tomcat using Java code? If it cant be platform dependent (or complicated or I have to do a "IF" for each), then only for Windows.
Thanks
What is the best way to start/stop/restart Apache Tomcat using Java code? If it cant be platform dependent (or complicated or I have to do a "IF" for each), then only for Windows.
Thanks
I know how to do this in linux, but it might be similar in windows,
so say you have your Tomcat shell script in your init.d directory, your command should be
service Tomcat {start|stop|restart}
then to run it in java you might want something like:
String cmd = "service Tomcat {start|stop|restart}";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
//from here only if you want to read the command output
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line=buf.readLine())!=null) {
System.out.println(line);
}
so basically replace the cmd variable with whatever command you use to start your server in the command prompt or terminal
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.