94

I want to start debug mode for my application. But I need to start the debug mode from command prompt. Is it possible ? And will the procedure vary between tomcat 5.5 to tomcat 6.?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Karthi
  • 1,161
  • 1
  • 9
  • 11

10 Answers10

135

On windows

$ catalina.bat jpda start
On Linux/Unix
$ catalina.sh jpda start

More info ----> https://cwiki.apache.org/confluence/display/TOMCAT/Developing

Brian J. Miller
  • 2,169
  • 1
  • 12
  • 12
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • Thanks, this helped me to setup the debug option in `startup.sh`. Editing the last line in `tomcat/bin/startup.sh` to `exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"`. I always forget to start in debug mode and I can save a 5minute restart. – TomasZ. Dec 22 '17 at 08:01
60

For windows first set variables:

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

to start server in debug mode:

%TOMCAT_HOME%/bin/catalina.bat jpda start

For unix first export variables:

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

and to start server in debug mode:

%TOMCAT_HOME%/bin/catalina.sh jpda start
krzysiek.ste
  • 2,246
  • 1
  • 26
  • 24
29
  1. From your IDE, create a remote debug configuration, configure it for the default JPDA Tomcat port which is port 8000.

  2. From the command line:

    Linux:

    cd apache-tomcat/bin
    export JPDA_SUSPEND=y
    ./catalina.sh jpda run
    

    Windows:

    cd apache-tomcat\bin
    set JPDA_SUSPEND=y
    catalina.bat jpda run
    
  3. Execute the remote debug configuration from your IDE, and Tomcat will start running and you are now able to set breakpoints in the IDE.

Note:

The JPDA_SUSPEND=y line is optional, it is useful if you want that Apache Tomcat doesn't start its execution until step 3 is completed, useful if you want to troubleshoot application initialization issues.

Peter
  • 3,067
  • 2
  • 17
  • 18
Jaime Hablutzel
  • 6,117
  • 5
  • 40
  • 57
16

A short answer is to add the following options when the JVM is started.

JAVA_OPTS=" $JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8080"
Jahan Zinedine
  • 14,616
  • 5
  • 46
  • 70
  • When using JAVA_OPTS -Xdebug you need not start catalina with jpda. Otherwise you may end up with this `ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.` – lnarasimhan Nov 17 '17 at 21:40
6

First, Navigate to the TOMCAT-HOME/bin directory.

Then, Execute the following in the command-line:

catalina.bat jpda start

If the Tomcat server is running under Linux, just invoke the catalina.sh program

catalina.sh jpda start

It's the same for Tomcat 5.5 and Tomcat 6

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
4

These instructions worked for me on apache-tomcat-8.5.20 on mac os 10.13.3 using jdk1.8.0_152:

$ cd /path/to/apache-tomcat-8.5.20/bin
$ export JPDA_ADDRESS="localhost:12321"
$ ./catalina.sh jpda run

Now connect to port 12321 from IntelliJ/Eclipse and enjoy remote debugging.

user674669
  • 10,681
  • 15
  • 72
  • 105
3

There are two ways to run tomcat in debug mode

  1. Using jdpa run

  2. Using JAVA_OPTS

First setup the environment. Then start the server using following commands.

export JPDA_ADDRESS=8000

export JPDA_TRANSPORT=dt_socket

%TOMCAT_HOME%/bin/catalina.sh jpda start

sudo catalina.sh jpda start

refer this article for more information this is clearly define it

1

If you're wanting to do this via powershell on windows this worked for me

$env:JPDA_SUSPEND="y"

$env:JPDA_TRANSPORT="dt_socket"

/path/to/tomcat/bin/catalina.bat jpda start

MarkyMarksFunkyBunch
  • 1,060
  • 10
  • 10
0

Inside catalina.bat set the port on which you wish to start the debugger

if not "%JPDA_ADDRESS%" == "" goto gotJpdaAddress
set JPDA_ADDRESS=9001

Then you can simply start the debugger with

catalina.bat jpda 

Now from Eclipse or IDEA select remote debugging and start start debugging by connecting to port 9001.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
0

If you want to keep this always when your service is running, you should edit your bin/startup.sh. There add 'jpda' parameter right here

exec "$PRGDIR"/"$EXECUTABLE" jpda  start "$@"

instead of original

exec "$PRGDIR"/"$EXECUTABLE" start "$@"
Eljah
  • 4,188
  • 4
  • 41
  • 85