如何在Java中以编程方式启动Tomcat Server [英] How to start Tomcat Server programmatically in Java
本文介绍了如何在Java中以编程方式启动Tomcat Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以编程方式在JAVA中启动tomcat服务器.请帮助我
I want to start tomcat server programmatically in JAVA. Please help me
推荐答案
如果我对您的理解很好,那么您有兴趣对应用程序中的事件运行tomcat.在这种情况下,您可以编写自己的方法来运行tomcat.
If I understood you well, you are interested in running tomcat on your event from application. If it is the case, you can write your own method to run tomcat.
这是示例:
public void stopRunTomcat(){
try{
Socket s = new Socket(server,8005);
if(s.isConnected()){
PrintWriter print = new PrintWriter(s.getOutputStream(),true);
//Stop tomcat if it is already started
print.println("SHUTDOWN");
print.close();
s.close();
}
//Run tomcat
Runtime.getRuntime().exec(System.getProperty("catalina.home")+"\\bin\\startup.sh");
}catch (Exception ex){
ex.printStackTrace();
}
}
您必须在路径和OS中采用此代码.之后,您可以从必须引发tomcat的事件中调用此方法.
You have to adopt this code to your paths and OS. After that you can call this method from event which have to raise tomcat.
我希望能帮上忙.
这篇关于如何在Java中以编程方式启动Tomcat Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文