怎么用Java来实现控制Tomcat启动与停止
展开全部
停止
//如不能运行,请正确配置tomcat环境
public class conTomCat{
public void close() throws IOException
{
Process process = Runtime.getRuntime().exec('cmd /c D:\\apache-tomcat-7.0.16\\bin\\shutdown.bat'); // 调用外部程序
final InputStream in = process.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringBuilder buf = new StringBuilder();
String line = null;
while((line = br.readLine()) != null)
buf.append(line);
System.out.println('输出结果为:' + buf);
}
启动
public void start() throws IOException
{
Process process = Runtime.getRuntime().exec('cmd /c D:\\apache-tomcat-7.0.16\\bin\\startup.bat'); // 调用外部程序
final InputStream in = process.ge tInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringBuilder buf = new StringBuilder();
String line = null;
while((line = br.readLine()) != null)
buf.append(line);
System.out.println('输出结果为:' + buf);
}
//如不能运行,请正确配置tomcat环境
public class conTomCat{
public void close() throws IOException
{
Process process = Runtime.getRuntime().exec('cmd /c D:\\apache-tomcat-7.0.16\\bin\\shutdown.bat'); // 调用外部程序
final InputStream in = process.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringBuilder buf = new StringBuilder();
String line = null;
while((line = br.readLine()) != null)
buf.append(line);
System.out.println('输出结果为:' + buf);
}
启动
public void start() throws IOException
{
Process process = Runtime.getRuntime().exec('cmd /c D:\\apache-tomcat-7.0.16\\bin\\startup.bat'); // 调用外部程序
final InputStream in = process.ge tInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(in));
StringBuilder buf = new StringBuilder();
String line = null;
while((line = br.readLine()) != null)
buf.append(line);
System.out.println('输出结果为:' + buf);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询