aspose file tools*
The moose likes Tomcat and the fly likes Start and Stop tomcat from Java Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Start and Stop tomcat from Java Program" Watch "Start and Stop tomcat from Java Program" New topic
Author

Start and Stop tomcat from Java Program

Kshitij Chandrasen
Greenhorn

Joined: Oct 11, 2010
Posts: 8
Hi,
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\logging.properties", 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
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Start and Stop tomcat from Java Program