Java 无法通过 IntelliJ 打开调试器端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40576115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:48:59  来源:igfitidea点击:

Unable to open debugger port through IntelliJ

javadebuggingintellij-ideajarremote-debugging

提问by Leonardo

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

我有一个在 DigitalOcean 上运行的服务器和一个我想要调试的 JAR 文件。我首先使用远程服务器上的 JAR 启动

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

但是在控制台上我看不到像“侦听端口 5005...”这样的输出。

When I press debug in IntelliJ it says

当我在 IntelliJ 中按下调试时,它说

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

无法打开调试器端口 (198.xxx.xxx.xx:5005):java.net.ConnectException“连接被拒绝”

This is my IntelliJ configuration:
enter image description here

这是我的 IntelliJ 配置:
在此处输入图片说明

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

我也试过使用,-Xdebug但还是不行。

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

如果我设置suspend=y它应该等到连接调试器,但相反,它启动时没有问题。

采纳答案by Ashutosh Jindal

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 5005on the machine where the server JAR is being executed. The telnetwill fail if that port is not being used.

在调试模式下启动远程 Java 进程的命令看起来是正确的。如果您在启动服务器 JAR 时没有看到“Listening to Port blah”,那么这可能意味着没有选择调试参数。另一种快速检查的方法telnet localhost 5005是在正在执行服务器 JAR 的机器上测试。telnet如果未使用该端口,则将失败。

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

回答by Vidya Priyadarshini

This command worked for me:

这个命令对我有用:

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

回答by jacob

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.

就我而言,这是因为在设置 -> 构建、执行、部署 -> 调试器下,我有一个内置服务器在与我试图将调试器连接到的端口相同的端口上运行。

回答by suifengpiao14

this command worked for me:

这个命令对我有用:

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

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.

并发布端口 5005。