Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Apache Tomcat 8 in debug mode?

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 ?

like image 221
TharinduKetipe Avatar asked May 03 '15 07:05

TharinduKetipe


People also ask

What is the debug port for Tomcat?

By default tomcat running port is 8080. So for the debugger, I will allocate port 8081. For that, you can select any port except tomcat running port or any other allocated ports in your localhost for other running servers.


4 Answers

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
like image 110
sendon1982 Avatar answered Oct 05 '22 04:10

sendon1982


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.

like image 31
Sridhar Sarnobat Avatar answered Oct 05 '22 03:10

Sridhar Sarnobat


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.

like image 31
Jaroslav Záruba Avatar answered Oct 05 '22 03:10

Jaroslav Záruba


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

like image 22
Dimitar II Avatar answered Oct 05 '22 03:10

Dimitar II