How to run Apache Tomcat 8 in debug mode?
Asked Answered
E

5

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 ?

Espinoza answered 3/5, 2015 at 7:55 Comment(3)
Are you using this option as well in Java options : -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y ? If yes, no need to start tomcat with jpda (sh catalina.sh jpda start), start it without the jpda option.Mccorkle
Yes. I'm using that method.Espinoza
Please don't use jpda while starting tomcat then.Mccorkle
C
10

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.

Currey answered 29/6, 2017 at 20:45 Comment(0)
Q
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
Quaint answered 10/7, 2017 at 4:57 Comment(0)
P
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.

Polinski answered 3/6, 2016 at 8:7 Comment(0)
B
2

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'.

Bevon answered 4/6, 2019 at 6:55 Comment(0)
H
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"
Hepatica answered 4/8, 2022 at 1:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.