0

I looked at this post,and they said to use a batch script to restart a tomcat server using a webapp. The issue is that if you use Runtime.exec("batch.bat"), once you do the kill for the tomcat server, the server dies and the runtime dies.

I did a quick test of this by adding some prints to my batch file to be sure:

echo "lol" > file1.txt
net stop tomcatservice
echo "lol2" > file2.txt
net start tomcatservice
echo "lol3" > file3.txt

Only file1 was created as suspected.

Is there a way to do what I want? Is there a way for me to restart the tomcat server on a schedule through code in my webapp?

Community
  • 1
  • 1
Jdban101
  • 367
  • 1
  • 3
  • 21

2 Answers2

1

Create a batch file and write shutdown.bat followed by startup.bat. Call that batch file from your java code using Runtime. It should do the trick for you.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
1

Use Runtime.exec("cmd /c start batch.bat") it starts a new process so it wont be terminated when the server stops.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68