Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
757 views
in Technique[技术] by (71.8m points)

java - how to restart tomcat from a running webapp?

I need to restart tomcat service from a webapp running on this tomcat. So I'm trying to execute script that stops tomcat service, and then starts it:

echo "before stop" >> textfile.txt
NET STOP "Tomcat7"

:loop
    timeout 3
    SC query Tomcat7 | FIND "STATE" | FIND "RUNNING" > NUL

IF ERRORLEVEL 1 (
    goto start
) ELSE (
    goto loop
)

:start
    NET START "Tomcat7"

Java code:

   String command = "C:\Tomcat 7.0\bin\restart.bat";
   Process p = Runtime.getRuntime().exec(command);

Tomcat is stopped, but not started. If I run this batch from command line, it works properly.

thank you for your time

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What you are asking is not exactly safe and possible but do take a look at Tomcat manager API that allows you to programmatically manipulate Tomcat deployment and instance:

http://tomcat.apache.org/tomcat-7.0-doc/api/index.html

http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/manager/host/HostManagerServlet.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...