RE: Starting/Stopping Tomcat from Java program

2010-10-15 Thread dB .
Since the question is how to do this from Java, don't go shelling out net 
start/stop on Windows :) Use JNA (http://jna.dev.java.net) , someone just 
recently committed complete support for Windows services. Stopping a service 
looks like this:

W32ServiceManager serviceManager = new W32ServiceManager();
W32Service service = serviceManager.openService(tomcat, 
Winsvc.SERVICE_ALL_ACCESS);
service.stopService();
service.close();

-dB.

dB. @ dblock.org 
Moscow|Geneva|Seattle|New York



-Original Message-
From: André Warnier [mailto:a...@ice-sa.com] 
Sent: Monday, October 11, 2010 9:34 AM
To: Tomcat Users List
Subject: Re: Starting/Stopping Tomcat from Java program

Hi.

I do not really understand the issue here.
If you are under Windows, with Tomcat running as a Service, then you can just 
run the commands net start tomcat6 / net stop tomcat6 to start/stop tomcat.
If you are under Linux, then you can just issue the command 
/etc/init.d/tomcat6 (start|stop).
Under most Unixes, the procedure is similar.
So where is the problem ?


Rob Gregory wrote:
 I call the scripts via code to both stop and start Tomcat. There is a 
 problem with even calling these scripts via Unix unless you change 
 (cd) into the bin directory before running startup.sh as the log paths 
 are generated relative to the startup.sh location.
 
 
   String strCatalinaBin = System.getenv(CATALINA_HOME) + \\bin\\;
   File objDir = new File(strCatalinaBin);
   r = Runtime.getRuntime();
   p = r.exec(new String[] { cmd.exe, /C, start, strCatalinaBin + 
 catalina.bat, start }, null, objDir);
 
   p.waitFor();
   p.destroy();
 
 Hope this helps.
 Rob
 
 
 -Original Message-
 From: Karthik Nanjangude [mailto:karthik.nanjang...@xius-bcgi.com]
 Sent: 11 October 2010 13:26
 To: Tomcat Users List
 Subject: RE: Starting/Stopping Tomcat from Java program

 Hi

 Probably u may need to use Embedded version of TOMCAT to do this
 activity...


 With regards
 karthik

 -Original Message-
 From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
 Sent: Monday, October 11, 2010 2:49 PM
 To: users@tomcat.apache.org
 Subject: Starting/Stopping Tomcat from Java program

 Hi,
 I've to write methods on calling which i'd be able to start and stop
 the
 tomcat app server. I tried this -
 I'm using Tomcat 6.0.26.
 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!



 --
 Kshitij Chandrasen
 Engineer, Software Engineering,
 Cisco Systems, CBSBU Engineering.



 --
 Kshitij Chandrasen
 Engineer, Software Engineering,
 Cisco Systems, CBSBU Engineering.

 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org
 
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org
 
 


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Starting/Stopping Tomcat from Java program

2010-10-13 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Rob,

On 10/11/2010 8:43 AM, Rob Gregory wrote:
 I call the scripts via code to both stop and start Tomcat. There is a
 problem with even calling these scripts via Unix unless you change (cd)
 into the bin directory before running startup.sh as the log paths are
 generated relative to the startup.sh location.

The cwd of the process is irrelevant: the script determines the Tomcat
directory from the location of the script itself.

   String strCatalinaBin = System.getenv(CATALINA_HOME) +
 \\bin\\;
   File objDir = new File(strCatalinaBin);
   r = Runtime.getRuntime();
   p = r.exec(new String[] { cmd.exe, /C, start,
 strCatalinaBin + catalina.bat, start }, null, objDir);

Note that you are not invoking catalina.bat directly, but instead
invoking the start command to invoke catalina.bat.

   p.waitFor();
   p.destroy();

This may stall if the script generates more than a trivial amount of
input. It's always best to drain both the stdout and stderr streams of
any process you launch in order to avoid hangups.

- -chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky1/rQACgkQ9CaO5/Lv0PDFbACgn6vDOcb0IswVezPZ0NwRdIWi
hZEAoJWH8NM9czRxSY49nO7uzPJxTZ0q
=yWZ2
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Starting/Stopping Tomcat from Java program

2010-10-11 Thread Karthik Nanjangude
Hi

Probably u may need to use Embedded version of TOMCAT to do this activity...



With regards
karthik

-Original Message-
From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
Sent: Monday, October 11, 2010 2:49 PM
To: users@tomcat.apache.org
Subject: Starting/Stopping Tomcat from Java program


 Hi,
 I've to write methods on calling which i'd be able to start and stop the 
 tomcat app server. I tried this -
 I'm using Tomcat 6.0.26.
 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!



 --
 Kshitij Chandrasen
 Engineer, Software Engineering,
 Cisco Systems, CBSBU Engineering.




--
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Starting/Stopping Tomcat from Java program

2010-10-11 Thread Rob Gregory
I call the scripts via code to both stop and start Tomcat. There is a
problem with even calling these scripts via Unix unless you change (cd)
into the bin directory before running startup.sh as the log paths are
generated relative to the startup.sh location.


String strCatalinaBin = System.getenv(CATALINA_HOME) +
\\bin\\;
File objDir = new File(strCatalinaBin);
r = Runtime.getRuntime();
p = r.exec(new String[] { cmd.exe, /C, start,
strCatalinaBin + catalina.bat, start }, null, objDir);

p.waitFor();
p.destroy();

Hope this helps.
Rob


 -Original Message-
 From: Karthik Nanjangude [mailto:karthik.nanjang...@xius-bcgi.com]
 Sent: 11 October 2010 13:26
 To: Tomcat Users List
 Subject: RE: Starting/Stopping Tomcat from Java program
 
 Hi
 
 Probably u may need to use Embedded version of TOMCAT to do this
activity...
 
 
 
 With regards
 karthik
 
 -Original Message-
 From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
 Sent: Monday, October 11, 2010 2:49 PM
 To: users@tomcat.apache.org
 Subject: Starting/Stopping Tomcat from Java program
 
 
  Hi,
  I've to write methods on calling which i'd be able to start and stop
the
 tomcat app server. I tried this -
  I'm using Tomcat 6.0.26.
  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!
 
 
 
  --
  Kshitij Chandrasen
  Engineer, Software Engineering,
  Cisco Systems, CBSBU Engineering.
 
 
 
 
 --
 Kshitij Chandrasen
 Engineer, Software Engineering,
 Cisco Systems, CBSBU Engineering.
 
 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Starting/Stopping Tomcat from Java program

2010-10-11 Thread kshitij chandrasen
Rob,
Is the snippet working for you? For me it opens a command prompt from which
it does call catalina.bat, but strangely the cmd window in which
catalina.bat is running is just like a normal cmd window without tomcat
output. The Tomcat did not start either.
Thanks
Kshitij

On Mon, Oct 11, 2010 at 6:13 PM, Rob Gregory rob.greg...@ibsolutions.comwrote:

 I call the scripts via code to both stop and start Tomcat. There is a
 problem with even calling these scripts via Unix unless you change (cd)
 into the bin directory before running startup.sh as the log paths are
 generated relative to the startup.sh location.


String strCatalinaBin = System.getenv(CATALINA_HOME) +
 \\bin\\;
File objDir = new File(strCatalinaBin);
r = Runtime.getRuntime();
p = r.exec(new String[] { cmd.exe, /C, start,
 strCatalinaBin + catalina.bat, start }, null, objDir);

p.waitFor();
p.destroy();

 Hope this helps.
 Rob


  -Original Message-
  From: Karthik Nanjangude [mailto:karthik.nanjang...@xius-bcgi.com]
  Sent: 11 October 2010 13:26
  To: Tomcat Users List
  Subject: RE: Starting/Stopping Tomcat from Java program
 
  Hi
 
  Probably u may need to use Embedded version of TOMCAT to do this
 activity...
 
 
 
  With regards
  karthik
 
  -Original Message-
  From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
  Sent: Monday, October 11, 2010 2:49 PM
  To: users@tomcat.apache.org
  Subject: Starting/Stopping Tomcat from Java program
 
  
   Hi,
   I've to write methods on calling which i'd be able to start and stop
 the
  tomcat app server. I tried this -
   I'm using Tomcat 6.0.26.
   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!
  
  
  
   --
   Kshitij Chandrasen
   Engineer, Software Engineering,
   Cisco Systems, CBSBU Engineering.
  
  
 
 
  --
  Kshitij Chandrasen
  Engineer, Software Engineering,
  Cisco Systems, CBSBU Engineering.
 
  -
  To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
  For additional commands, e-mail: users-h...@tomcat.apache.org


 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org




-- 
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.


Re: Starting/Stopping Tomcat from Java program

2010-10-11 Thread André Warnier

Hi.

I do not really understand the issue here.
If you are under Windows, with Tomcat running as a Service, then you can just run the 
commands net start tomcat6 / net stop tomcat6 to start/stop tomcat.
If you are under Linux, then you can just issue the command /etc/init.d/tomcat6 
(start|stop).

Under most Unixes, the procedure is similar.
So where is the problem ?


Rob Gregory wrote:

I call the scripts via code to both stop and start Tomcat. There is a
problem with even calling these scripts via Unix unless you change (cd)
into the bin directory before running startup.sh as the log paths are
generated relative to the startup.sh location.


String strCatalinaBin = System.getenv(CATALINA_HOME) +
\\bin\\;
File objDir = new File(strCatalinaBin);
r = Runtime.getRuntime();
p = r.exec(new String[] { cmd.exe, /C, start,
strCatalinaBin + catalina.bat, start }, null, objDir);

p.waitFor();
p.destroy();

Hope this helps.
Rob



-Original Message-
From: Karthik Nanjangude [mailto:karthik.nanjang...@xius-bcgi.com]
Sent: 11 October 2010 13:26
To: Tomcat Users List
Subject: RE: Starting/Stopping Tomcat from Java program

Hi

Probably u may need to use Embedded version of TOMCAT to do this

activity...



With regards
karthik

-Original Message-
From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
Sent: Monday, October 11, 2010 2:49 PM
To: users@tomcat.apache.org
Subject: Starting/Stopping Tomcat from Java program


Hi,
I've to write methods on calling which i'd be able to start and stop

the

tomcat app server. I tried this -

I'm using Tomcat 6.0.26.
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!



--
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.




--
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org





-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Starting/Stopping Tomcat from Java program

2010-10-11 Thread Michael Knümann

 Hi,

perhaps this has the solution out of the box:

http://cargo.codehaus.org/


Michael


Hi.

I do not really understand the issue here.
If you are under Windows, with Tomcat running as a Service, then you 
can just run the commands net start tomcat6 / net stop tomcat6 to 
start/stop tomcat.
If you are under Linux, then you can just issue the command 
/etc/init.d/tomcat6 (start|stop).

Under most Unixes, the procedure is similar.
So where is the problem ?


Rob Gregory wrote:

I call the scripts via code to both stop and start Tomcat. There is a
problem with even calling these scripts via Unix unless you change (cd)
into the bin directory before running startup.sh as the log paths are
generated relative to the startup.sh location.


String strCatalinaBin = System.getenv(CATALINA_HOME) +
\\bin\\;
File objDir = new File(strCatalinaBin);
r = Runtime.getRuntime();
p = r.exec(new String[] { cmd.exe, /C, start,
strCatalinaBin + catalina.bat, start }, null, objDir);

p.waitFor();
p.destroy();

Hope this helps.
Rob



-Original Message-
From: Karthik Nanjangude [mailto:karthik.nanjang...@xius-bcgi.com]
Sent: 11 October 2010 13:26
To: Tomcat Users List
Subject: RE: Starting/Stopping Tomcat from Java program

Hi

Probably u may need to use Embedded version of TOMCAT to do this

activity...



With regards
karthik

-Original Message-
From: kshitij chandrasen [mailto:kshtjchnd...@gmail.com]
Sent: Monday, October 11, 2010 2:49 PM
To: users@tomcat.apache.org
Subject: Starting/Stopping Tomcat from Java program


Hi,
I've to write methods on calling which i'd be able to start and stop

the

tomcat app server. I tried this -

I'm using Tomcat 6.0.26.
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!



--
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.




--
Kshitij Chandrasen
Engineer, Software Engineering,
Cisco Systems, CBSBU Engineering.

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org





-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org




--
Michael Knümann
Senior Consultant
BusinessCoDe GmbH
Ollenhauerstr.1 D-53113 Bonn

Geschäftsführer:
Hanno Gehron, Joerg Kunze
HRB 008660 - Sitz Bonn

Office Phone:   +49 (0) 228 / 33885-242
Mobile Phone:   +49 (0) 174 / 3178178
Fax:+49 (0) 228 / 33885--225

EMail: m...@business-code.de
http://www.business-code.de


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org