java写tomcat启动_怎么用java写一个tomcat的启动、停止程序?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

package com.freesky.cm.bankinterface.ws; import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader; public class TestTomcat { @SuppressWarnings("static-access")

public static void main(String[] args) {

try {

//shutdown();

//Thread.currentThread().sleep(1000);

//startup();

//reStart();

} catch (Exception e) { }

}

public static void reStart(String cmd,String cmd1){

try {

Runtime rt = Runtime.getRuntime();

//String cmd = "cmd.exe /c d:&cd F:\\JAVA\\apache-tomcat-6.0.14\\bin\\&start startup.bat&start shutdown.bat";

//String cmd = "cmd.exe /c f:&cd F:\\JAVA\\apache-tomcat-6.0.14\\bin&start shutdown.bat&taskkill /f /im cmd.exe";

//String cmd1 = "cmd.exe /c f:&cd F:\\JAVA\\apache-tomcat-6.0.14\\bin&start startup.bat&taskkill /f /im cmd.exe"; Process process = rt.exec(cmd);

InputStream in = process.getInputStream();

InputStreamReader isr = new InputStreamReader(in);

BufferedReader br = new BufferedReader(isr);

String line;

StringBuffer sb = new StringBuffer();

while ((line = br.readLine()) != null) {

sb.append(line);

sb.append("
");

}

in.close();

isr.close();

br.close();

process.waitFor();

Thread.currentThread().sleep(3000);

Process process1=rt.exec(cmd1);

InputStream in1 = process.getInputStream();

InputStreamReader isr1 = new InputStreamReader(in1);

BufferedReader br1 = new BufferedReader(isr1);

String line1;

StringBuffer sb1 = new StringBuffer();

while ((line1 = br1.readLine()) != null) {

sb1.append(line);

sb1.append("
");

}

in1.close();

isr1.close();

br1.close();

process1.waitFor();

System.out.println("command output:
" + sb.toString());

}

catch(Exception ioe) {

System.out.println(ioe.getMessage());

}

}

public static void shutdown(String cmd){

try {

Runtime rt = Runtime.getRuntime();

//String cmd = "cmd.exe /c d:&cd D:\\service\\apache-tomcat-6.0.14\\bin&start shutdown.bat&start startup.bat";

//String cmd = "cmd.exe /c f:&cd F:\\JAVA\\apache-tomcat-6.0.14\\bin&start shutdown.bat&taskkill /f /im cmd.exe";

Process process = rt.exec(cmd);

InputStream in = process.getInputStream();

InputStreamReader isr = new InputStreamReader(in);

BufferedReader br = new BufferedReader(isr);

String line;

StringBuffer sb = new StringBuffer();

while ((line = br.readLine()) != null) {

sb.append(line);

sb.append("
");

}

in.close();

isr.close();

br.close();

process.waitFor();

System.out.println("command output:
" + sb.toString());

}

catch(Exception ioe) {

System.out.println(ioe.getMessage());

}

}

public static void startup(String cmd){

try {

Runtime rt = Runtime.getRuntime();

//String cmd = "cmd.exe /c d:&cd D:\\service\\apache-tomcat-6.0.14\\bin&start shutdown.bat&start startup.bat";

// cmd = "cmd.exe /C f:&cd F:\\JAVA\\apache-tomcat-6.0.14\\bin&start startup.bat&taskkill /f /im cmd.exe";

Process process = rt.exec(cmd);

InputStream in = process.getInputStream();

InputStreamReader isr = new InputStreamReader(in);

BufferedReader br = new BufferedReader(isr);

String line;

StringBuffer sb = new StringBuffer();

while ((line = br.readLine()) != null) {

sb.append(line);

sb.append("
");

}

in.close();

isr.close();

br.close();

process.waitFor();

System.out.println("command output:
" + sb.toString());

}

catch(Exception ioe) {

System.out.println(ioe.getMessage());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值