如何用java代码启动tomcat

cslgwufeng 2006-09-27 11:01:34
我想做个启动程序,其中启动过程中启动tomcat,请各位大哥们帮帮小弟
...全文
356 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyhlgx 2006-09-27
  • 打赏
  • 举报
回复
注意要设置CLASSPATH,JAVA_HOME,TOMCAT_HOME
wyhlgx 2006-09-27
  • 打赏
  • 举报
回复
直接调startup.bat文件.
import java.io.IOException;
import java.io.InputStream;

public class TestProcess {
public static void main(String[] args) {
String command = "E:\\Server\\apache-tomcat-5.5.17\\bin\\startup.bat";
try {
Process child = Runtime.getRuntime().exec(command);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(c);//如果你不需要看输出,这行可以注销掉
}
in.close();
try {
child.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
闭门车 2006-09-27
  • 打赏
  • 举报
回复
不懂,mark!!!
cslgwufeng 2006-09-27
  • 打赏
  • 举报
回复
在IE中输入http://localhost:8080/
还是没有tomcat 欢迎界面
cslgwufeng 2006-09-27
  • 打赏
  • 举报
回复
代码可以运行.我将tomcat 的startup.bat 的路径也改为了自己电脑的路径改后为:
package com;

import java.lang.Runtime;

import java.io.IOException;
import java.io.InputStream;

public class TestProcess {
public static void main(String[] args) {
String command = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.0\\bin\\startup.bat";
try {
Process child = Runtime.getRuntime().exec(command);
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(c);//如果你不需要看输出,这行可以注销掉
}
in.close();
try {
child.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("done");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
运行后的结果为:
84104101326765846576737865957279776932101110118105114111110109101110116321189711410597981081013210511532110111116321001011021051101011003299111114114101991161081211310841041051153210111011810511411111010910111011632118971141059798108101321051153211010110110010110032116111321141171103211610410511532112114111103114971091310done
但是我在服务里那个Apache Tomcat 却没有启动啊.

Sunny319 2006-09-27
  • 打赏
  • 举报
回复
学习一下!

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧