import java.io.IOException;
import java.io.InputStream;
/**
* 程序启动Tomcat
* @author RuiLin.Xie - xKF24276
*
*/
public class Main extends Thread
{
/** cmd命令 **/
public String cmd;
public static void main(String[] args) throws IOException, InterruptedException
{
/** 启动 **/
Main startup = new Main();
startup.cmd = "cmd /c start.bat";
startup.start();
//启动10秒后自动退出
Thread.sleep(10000);
/** 关闭 **/
Main shutdown = new Main();
shutdown.cmd = "cmd /c stop.bat";
shutdown.start();
}
public void run()
{
try
{
//得到进程
Process process = Runtime.getRuntime().exec(cmd);
//获得输入流
InputStream in = process.getInputStream();
byte[] b = new byte[1024];
while((in.read(b)) != -1)
{
String msg = new String(b);
System.out.println(msg);
}
}
catch(IOException ie)
{
ie.printStackTrace();
}
}
/**
* start.bat放在项目根目录下,tomcat也放在同级目录下
* start.bat内容:
* ================
cd tomcat
cd bin
startup.bat
* ================
*
* stop.bat内容:
* ================
cd tomcat
cd bin
shutdown.bat
* ================
*
*
*
* Tomcat配置JAVA_HOME路径,无需设置环境变量:
* 将JDK复制到Tomcat根目录下,修改bin目录下的startup.bat与shutdown.bat文件
* 在CATALINA_HOME赋值后下面增加一句:set JAVA_HOME=%CATALINA_HOME%\jdk6
*/
}
程序里启动Tomcat
最新推荐文章于 2022-05-17 16:42:51 发布