Tuesday, August 30, 2022

[SOLVED] Remote debugging in Tomcat 7 and CentOS 7

Issue

I'm trying to setup remote debugging from IntelliJ to a Tomcat, but forget IntelliJ for now because I haven't started with that. I'm trying to set it up on the server initially, I'm trying to setup tomcat so that it can accept those connections but when I add the jdwp flags/arguments, tomcat won't start with the following error.

May 27 23:02:58 lab5 server: ERROR: transport error 202: bind failed: Permission denied
May 27 23:02:58 lab5 server: ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)    
May 27 23:02:58 lab5 server: JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
May 27 23:02:58 lab5 systemd: tomcat.service: main process exited, code=exited, status=2/INVALIDARGUMENT        
May 27 23:02:58 lab5 systemd: Unit tomcat.service entered failed state.
May 27 23:02:58 lab5 systemd: tomcat.service failed.

I've tried multiple ways.

-Xdebug -Xrunjdwp:transport=dt_socket,address=myec2privateip:2345,server=y,suspend=n \
-agentlib:jdwp=transport=dt_socket,address=myec2privateip:2345,suspend=y,server=n \
-agentlib:jdwp=transport=dt_socket,address=myec2privateip:2345,suspend=y,server=y \
-agentlib:jdwp=transport=dt_socket,address=myec2privateip:2345,suspend=n,server=y \
-agentlib:jdwp=transport=dt_socket,address=myec2privateip:2345,suspend=n,server=n \
-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n
-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=myec2privateip:2000,suspend=n \
# JPDA_ADDRESS=myec2privateip:32702
# JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=32702"
-agentlib:jdwp=transport=dt_socket,server=y,address=8000 \
-agentlib:jdwp=transport=dt_socket,server=y,address=*:8000,suspend=n \
JAVA_TOOL_OPTIONS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
agentlib:jdwp=transport=dt_socket,address=localhost:39621,suspend=n,server=y -Xdebug
-Xdebug -agentlib:jdwp=transport=dt_socket,address=2345,server=y,suspend=n -Djava.security.debug=all

For the ports I've tried above, there's nothing running on them. This is not an issue of connection timing out, it's not an issue of firewalls etc.

The Tomcat is on an AWS EC2 instance with the following CentOS AMI "CentOS Linux 7 x86_64 HVM EBS 1602"

The Tomcat I have installed is from yum, "tomcat-7.0.92-1.el7.noarch"

Java version

  • OpenJDK version "1.8.0_242"
  • OpenJDK Runtime Environment (build 1.8.0_242-b08)
  • OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

The Tomcat is working perfectly fine if I remove the arguments I've been adding.

Why might this error be happening, and why can't I get Tomcat to start with any of these?

I've been setting it mostly in /etc/sysconfig/tomcat under JAVA_OPTS, but have tried other locations.


Solution

For anyone else doing this on Centos7 and having the same issue, after trying a million things, this is the thing that solved it... as answered by Mikematic here https://stackoverflow.com/a/56536805/13223528

This has nothing to do with the Tomcat configuration. It is the SELinux on RHEL and CentOS boxes preventing the read write permissions on folders not associated with default tomcat installation. To fix this, install the SELinux management tool and set permissive for tomcat_t SELinux type.

yum install selinux-policy-devel

semanage permissive -a tomcat_t


Answered By - namrogom
Answer Checked By - Robin (WPSolving Admin)