32

I've got a server running on DigitalOcean and a JAR file that I want to debug. I first start the JAR on the remote server using

java -jar Server.jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

but on the console I see no output like "listening on port 5005...".

When I press debug in IntelliJ it says

unable to open debugger port (198.xxx.xxx.xx:5005): java.net.ConnectException "Connection refused"

This is my IntelliJ configuration:
enter image description here

I also tried using -Xdebug but it still didn't work.

If I set suspend=y it should wait until a debugger is connected, but instead, it starts without problems.

12 Answers 12

21

The command to start the remote Java process in debug mode looks correct. If you don't see "Listening to Port blah" when you start the server JAR, then it might mean that the debug args are not being picked up. Another way to quickly check this would be to test with a telnet localhost 5005 on the machine where the server JAR is being executed. The telnet will fail if that port is not being used.

I suggest that you try the following, since the order of the parameters might be significant (I'll add some official evidence for this later):

java "agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005" -jar Server.jar
Sign up to request clarification or add additional context in comments.

2 Comments

I would just like to stress out the fact that the order of the parameters does matter.
Where is the official evidence? Huh? HUH? Joke.
20

this command worked for me:

export JAVA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005'

by default idea remote dialog suggest:

'agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005'

change it to:

'agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005'

and issues port 5005.

6 Comments

It worked for me, but I don't know why... Problem was with intellij connecting to tomcat inside docker container.
While connecting to remote server from Intellij IDEA, when I used export JAVA_OPTS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5505' it didn't work. But when I used address=0.0.0.0:5505 then it worked.
Lifesaver! Thank you. I spent last hour trying different configurations and all I was missing was "0.0.0.0" part before port
This in setenv '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5505' work for me
Adding "0.0.0.0:" makes it work! Thanks! But what's the difference did "0.0.0.0:" make?
|
5

This command worked for me:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar Server.jar 

1 Comment

pretty old thread but want to highlight one thing - I was using same command but had address=*:5005, I changed it to address=5005 and it worked like a charm
2

Thanks to suifengpiao14 but I'm going to describe the problem a bit more in detail.

I checked multiple things, and at the end found the reason: actually as like as a restful service we want to be accessible from out of the server we are running it that we should set 0.0.0.0 as the nameserver, here we should do a similar one. I checked the difference between the server from which I can remotely debug and the one which I can't. using netstat command:

for the server which I was ok with:

tcp        0      0 0.0.0.0:5005            0.0.0.0:*               LISTEN      8323/java

for the server which I had problem with:

tcp        0      0 127.0.0.1:5005            0.0.0.0:*               LISTEN      8323/java

So, using below jvm options should be helpful:

'agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
'agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005'

Comments

1

I've reproduced similar issue:

Unable to open debugger port (localhost:5005): java.net.ConnectException "Connection refused (Connection refused)" 

I had it while running debugger w/ command line arguments for remote JVM using Run/Debug configurations:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

by attaching IDE with exposed debug agent server.

Since I've used Kubernetes cluster, the reason was:

once the pod has been created and was running as expected, I needed to proceed to set up port forwarding with the kubectl port-forward command, with the port to expose locally for traffic from the application before running debugger.

Based on kubectl port-forward syntax:

kubectl port-forward <resource-type/resource-name> [local_port]:<pod_port>

In format like:

kubectl port-forward <pod-name> -n <namespace> 5005:5005

or in a shorter form:

kubectl port-forward <pod-name> 5005:5005

The client listens on port 5000 locally and forwards to 5000 in the pod.

Accordingly entrypoint.sh file of the service was configured w/ the following command for Kubernetes cluster:

java -Djava.security.egd.=file:/dev/./urandom -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -Xmx400m -jar /service.jar

As result, running port-forward before debugger solved the issue.

Comments

1

When running debugger port in tomcat, you should start the tomcat server with this command:

catalina.bat jpda start

Comments

0

In my case it was because under settings -> build, execution, deployment -> debugger I had a built in server running on the same port as which I was trying to attach my debugger to for some reason.

Comments

0

For people like me who sometimes forget to read...

Copy and paste the arguments to the command line when JVM is started
says the Run/Debug Configuration in IntelliJ, directly under:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

Means: Copy this line and go to your docker configuration. Add an environment variable (modify options dropdown). Paste it there with JAVA_OPTS= prepended.

Now when you did every correctly, you will have
Listening for transport dt_socket at address: 5005
and
Command line argument: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

This is who I solved it...

Comments

0

One of the reason is that the port is not enabled. You can try by enabling the port using the below command

firewall-cmd --zone=public --permanent --add-port=8001/tcp

Once the port is up, restart tomcat & try connecting again. Hope it helps.

Comments

0

This might help someone That port in JVM debug is not your web app port

Comments

0

this solved it for me:

net stop winnat

net start winnat

IntelliJ IDEA - Address localhost:1099 is already in use

Comments

0

Remote debugger needs to connect to the JVM that is already running in debug mode. Make sure you start the app you want to debug first with the JVM options suggested by the IDE. Then start Remote configuration to connect and debug this app. ~CrazyCoder

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.