10

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 ?

Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106

5 Answers5

9

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.

Gary Sheppard
  • 4,764
  • 3
  • 25
  • 35
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
8

You can just add env variable and run the tomcat as usual

Debug port is 8000 in this case

export CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"

Then run the tomcat

sh ./catalina.sh start
sendon1982
  • 9,982
  • 61
  • 44
2

This happened to me with Eclipse when I tried to add the debugging parameters (-Xdebug -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=y) so I could suspend Tomcat on start. Unfortunately I then launched my Tomcat (within Eclipse) using the Debug button.

Why this is a problem
When you are launching Tomcat in Debug mode Eclipse itself inserts the debug parameters. When you have your own debug parameters in the launch configuration you are indeed passing them twice.

So if you need to launch Tomcat from within Eclipse and suspend it on start (so you can connect with debugger) you need to:
- add the debugging parameters to the "Arguments -> VM arguments" box of your launch config,
- and then Run this config, not Debug.
This way only the debugging parameters from your launch config are added.

Jaroslav Záruba
  • 4,694
  • 5
  • 39
  • 58
1

There is alternative approach, recommended in 'catalina.sh':

"Do not set the variables in this script. Instead put them into a script setenv.sh in CATALINA_BASE/bin to keep your customizations separate."

For Windows, the file name with environment variables will be 'setenv.bat'.

Dimitar II
  • 2,299
  • 32
  • 33
0

Thank you mr Dimitar II
Verified this works perfectly and is consumed automatically when running startup.bat
file: setenv.bat

@echo off
rem The proper way to set environment up for running Catalina
set "CATALINA_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
Greg
  • 1,007
  • 1
  • 9
  • 9