要设置哪些 Java 命令行选项以允许远程调试 JVM?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/138511/
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 08:45:40  来源:igfitidea点击:

What are Java command line options to set to allow JVM to be remotely debugged?

javadebugging

提问by paulgreg

I know there's some JAVA_OPTSto set to remotely debug a Java program.

我知道有一些JAVA_OPTS设置可以远程调试 Java 程序。

What are they and what do they mean ?

它们是什么,它们是什么意思?

采纳答案by Hans Sjunnesson

I have this articlebookmarked on setting this up for Java 5 and below.

我将这篇文章加入了书签,用于为 Java 5 及更低版本进行设置。

Basically run it with:

基本上运行它

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044

For Java 5 and above, run it with:

对于Java 5 及更高版本,运行它:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044

回答by paulgreg

Before Java 5.0, use -Xdebugand -Xrunjdwparguments. These options will still work in later versions, but it will run in interpreted mode instead of JIT, which will be slower.

在 Java 5.0 之前,使用-Xdebug-Xrunjdwp参数。这些选项在以后的版本中仍然有效,但它将在解释模式下运行,而不是在 JIT 下运行,后者会更慢。

From Java 5.0, it is better to use the -agentlib:jdwpsingle option:

从 Java 5.0 开始,最好使用-agentlib:jdwp单个选项:

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

Options on -Xrunjdwpor agentlib:jdwparguments are :

-Xrunjdwpagentlib:jdwp参数的选项是:

  • transport=dt_socket: means the way used to connect to JVM (socket is a good choice, it can be used to debug a distant computer)
  • address=8000: TCP/IP port exposed, to connect from the debugger,
  • suspend=y: if 'y', tell the JVM to wait until debugger is attached to begin execution, otherwise (if 'n'), starts execution right away.
  • transport=dt_socket: 表示用于连接JVM的方式(socket是一个不错的选择,可以用来调试远程计算机)
  • address=8000: TCP/IP 端口暴露,从调试器连接,
  • suspend=y:如果'y',告诉JVM等待直到调试器被附加开始执行,否则(如果'n'),立即开始执行。

回答by thebiggestlebowski

For java 1.5 or greater:

对于 java 1.5 或更高版本:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

For java 1.4:

对于 Java 1.4:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

For java 1.3:

对于 Java 1.3:

java -Xnoagent -Djava.compiler=NONE -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 <YourAppName>

Here is output from a simple program:

这是一个简单程序的输出:

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 HelloWhirled
Listening for transport dt_socket at address: 1044
Hello whirled

回答by neves

Here is the easiest solution.

这是最简单的解决方案。

There are a lot of environment special configurations needed if you are using Maven. So, if you start your program from maven, just run the mvnDebugcommand instead of mvn, it will take care of starting your app with remote debugging configurated. Now you can just attach a debugger on port 8000.

如果您使用 Maven,则需要很多环境特殊配置。因此,如果您从 maven 启动您的程序,只需运行mvnDebug命令而不是mvn,它将负责启动您的应用程序并配置远程调试。现在您只需在端口 8000 上附加调试器即可。

It'll take care of all the environment problems for you.

它会为您解决所有环境问题。

回答by Antony Shumskikh

Since Java 9.0 JDWP supports only local connections by default. http://www.oracle.com/technetwork/java/javase/9-notes-3745703.html#JDK-8041435

由于 Java 9.0 JDWP 默认只支持本地连接。 http://www.oracle.com/technetwork/java/javase/9​​-notes-3745703.html#JDK-8041435

For remote debugging one should run program with *:in address:

对于远程调试,应该使用*:地址运行程序:

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

回答by Jovi Qiao

java

爪哇

java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8001,suspend=y -jar target/cxf-boot-simple-0.0.1-SNAPSHOT.jar

addressspecifies the port at which it will allow to debug

address指定允许调试的端口

Maven

马文

**Debug Spring Boot app with Maven:

**使用 Maven 调试 Spring Boot 应用程序:

mvn spring-boot:run -Drun.jvmArguments=**"-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8001"

回答by Santosh b

Command Line

命令行

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=PORT_NUMBER

Gradle

摇篮

gradle bootrun --debug-jvm

Maven

马文

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=PORT_NUMBER

回答by Boney

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=PORT_NUMBER

Here we just use a Socket Attaching Connector, which is enabled by default when the dt_socket transport is configured and the VM is running in the server debugging mode.

这里我们只使用了 Socket Attaching Connector,当配置了 dt_socket 传输并且 VM 在服务器调试模式下运行时,它默认启用。

For more details u can refer to : https://stackify.com/java-remote-debugging/

有关更多详细信息,您可以参考:https: //stackify.com/java-remote-debugging/