-1

I want to create batch file to start/stop catalina.bat file on window server.

@echo off
cls

cd D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin

catalina.bat start

this is what I create but not working.

James Z
  • 12,209
  • 10
  • 24
  • 44
Keshav Kalra
  • 1
  • 1
  • 5
  • 2
    How is it not working? Are there any error messages or is it that nothing happens? Have you tried running your batch file from the `cmd.exe` window? – user234461 Apr 23 '18 at 14:01
  • Typically we call a batch file. I suggest running this from cmdline first to ensure you do not have any `CATALINA_HOME` environment issues, if not it will work as is in a batch file. `call "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" start` – Gerhard Apr 23 '18 at 14:22
  • It worked.. sorry I was using some other argument – Keshav Kalra Apr 23 '18 at 15:12
  • @KeshavKalra, given that you responded above after I'd posted my answer I'd appreciate it if you provided feedback please. The `Call` method is only really necessary if you are returning to the same batch file upong completion of `catalina.bat` otherwise there's nothing stopping you from running the batch file directly as you had. – Compo Apr 23 '18 at 16:24

2 Answers2

0

If you type CD /? at the command prompt you'll note it has a /D option for changing drives.

You could therefore try:

@Echo Off
ClS
CD /D "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin"
catalina.bat start <args>

If you don't need to have your working directory as the \bin location you could just use:

@Echo Off
ClS
"D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" start <args>

To stop it, repeat the last line, ending it with stop instead of start

Edit

If you really do need to use it, and given that you said the Call command works, you could use…

Either:

@Echo Off
ClS

Rem start it
Call "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" start <args>

Rem Do some other stuff
Timeout 120 >Nul

Rem stop it
Call "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin\catalina.bat" stop

Or:

@Echo Off
ClS

Rem Make \bin directory current
CD /D "D:\apache-tomcat-7.0.75-windows-x86\apache-tomcat-7.0.75\bin"

Rem start it
Call catalina.bat start <args>

Rem Do some other stuff
Timeout 120 >Nul

Rem stop it
Call catalina.bat stop
Compo
  • 36,585
  • 5
  • 27
  • 39
0

If you want to create a .bat file to start your Tomcat, then here it goes:

  1. Declare the JAVA_HOME & CATALINA _HOME path in the system environment variables.

  2. Create a file in Notepad with the .bat extension and put the following code within the respective Tomcat directory:

    set JPDA_ADDRESS=8000
    set JPDA_TRANSPORT=dt_socket
    C:
    cd C:\Program Files\Apache Software Foundation\Tomcat 9.0 //Enter Your Tomacat Path
    call .\bin\catalina jpda start 
    

Check out the image attached for more detailed explanation.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77