java程序控制tomcat启动

来源:互联网 发布:windows cifs配置 编辑:程序博客网 时间:2024/05/06 08:28

package com.easy.zuboGUI;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

 

//java程序控制tomcat启动

//@author FKZ

//如不能运行,请正确配置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.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 static void main(String[] args) throws Exception{
  // TODO Auto-generated method stub

  conTomCat con=new conTomCat();
  con.start();
 
 }

}

0 0
原创粉丝点击