0

im using tomcat 7 , and im trying to do something nice. i want to have a little swing program to operate my current project (a site)

i wish to have in that swing application a button to run the server , shut the server and such.

i know there is the option of running it as soon as i start the application but i dont want it. i want to have the option to click a swing button and load it.

for that , i need to run the server by code.

is there a way to load tomcat server via code?

Bar Hoshen
  • 302
  • 1
  • 18
  • execute tomcat catalina.bat from program through runtime and cmd.exe – Ironluca Nov 27 '14 at 12:51
  • yes. Search for Process/ProcessBuilder on google and modify accordingly. – SMA Nov 27 '14 at 12:52
  • Tomcat actually has an API to boot it directly from Java code so you don't have to fiddle with spawning processes. See this related question: http://stackoverflow.com/questions/11669507/embedded-tomcat-7-servlet-3-0-annotations-not-working – Gimby Nov 27 '14 at 13:00

1 Answers1

0

A quick solution for this may be Using RunTime you can do this -

Runtime.getRuntime().exec("startup.bat");

similarly, to stop -

Runtime.getRuntime().exec("shutdown.bat");

Assuming both batch files exist in tomcat bin directory.

Ved
  • 8,577
  • 7
  • 36
  • 69
  • Actually i was looking for an tomcat API (im pretty sure theres a solution there) but this is a great easy answer. thank you. – Bar Hoshen Nov 27 '14 at 13:22