Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Start and Stop tomcat from Java Program

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 26065
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic