How to run Apache Tomcat 8 in debug mode?

TharinduKetipe picture TharinduKetipe · May 3, 2015 · Viewed 18.8k times · Source

I am trying to run Apache Tomcat 8.0.21 in debug mode.

When I give the command

sh catalina.sh jpda start

it gives this error.

error message

ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options. Error occurred during initialization of VM agent library failed to init: jdwp

Can anyone help ?

Answer

Sridhar Sarnobat picture Sridhar Sarnobat · Jun 29, 2017

Either

unset CATALINA_OPTS
unset JPDA_ADDRESS
unset JPDA_OPTS
unset JPDA_TRANSPORT

catalina.sh jpda start

Or

# in .bashrc, .profile etc.
export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -Djava.security.egd=file:/dev/urandom -Denv=dev -Xms1024M -Xmx2048M -XX:PermSize=256M -XX:MaxPermSize=768m"

# At your shell prompt
./startup.sh

Explanation

As Arnab said in the comments, if your shell configuration includes environment variables mentioning jdpw (such as CATALINA_OPTS, JDPA_ADDRESS, JPDA_OPTS), just launch using ./startup.sh as if you were not trying to do remote debugging and the script will pick up the jdpw option from your environment variables.

The launch option syntax catalina.sh jpda start should only be used if you don't have any environment variables that already specified a remote debug port. It's meant to be convenient but if you've previously configured your shell to support java remote debugging you're probably mixing the two alternative approaches.