Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!

  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Start and Stop tomcat from Java Program  RSS feed

Kshitij Chandrasen
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've to write programs on calling which i'd be able to start and stop the tomcat app server. I tried this -

String[] command = new String[4];
command[0] = "cmd";
command[1] = "/C";
command[2] = "startup.bat";
command[3] = "C:\\";
String x[] = {"PATH=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.26\\bin","CATALINA_HOME=C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 6.0.26","JAVA_HOME=C:\\Program Files\\Java\\jdk1.6.0_21","JRE_HOME=C:\\Program Files\\Java\\jre6"};
Process p = Runtime.getRuntime().exec(command,x);

This gives me a strange windows error saying - The system cannot find the file -Djava.util.logging.config.file="C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\conf\", while it actually exists.
If instead of setting the path, I give the absolute path of startup.bat in command[3], it works fine -
Process p = Runtime.getRuntime().exec("cmd /C start C:\\broadway\\bat\\startup.bat"); //I copied the startup.bat to a folder and ran it from there, it worked fine.
Please give me pointers to the right direction!
Tim Holloway
Posts: 18531
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Kshitij!

Actually, one of the more popular ways to get a Java program to run Tomcat is to have it run embedded. The Tomcat server can be instantiated as a JavaBean and launched directly instead of having to go through the shell interface. The JBoss appserver is an example of this.

However, if that's not appropriate, what I recommend is that you make your request less "Windows-like". The Windows file naming can make a mess of any Java application. So use the forward-slash path separator where you can and avoid file and directory names with spaces in them (like "Program Files").

I think you've also got a problem there because you're attempting to set up a classpath. The Tomcat script files set up the classpath themselves. However, you do have to have the environment variable "JAVA_HOME" set. Other Tomcat environment variables are usually optional.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!