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

本文翻译自:What are Java command line options to set to allow JVM to be remotely debugged?

I know there's some JAVA_OPTS to set to remotely debug a Java program. 我知道有一些JAVA_OPTS可以设置为远程调试Java程序。

What are they and what do they mean ? 它们是什么,它们是什么意思?


#1楼

参考:https://stackoom.com/question/a23/要设置哪些Java命令行选项以允许对JVM进行远程调试


#2楼

I have this article bookmarked 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

#3楼

Before Java 5.0, use -Xdebug and -Xrunjdwp arguments. 在Java 5.0之前,请使用-Xdebug-Xrunjdwp参数。 These options will still work in later versions, but it will run in interpreted mode instead of JIT, which will be slower. 这些选项在以后的版本中仍然可以使用,但是它将以解释模式而不是JIT运行,这会比较慢。

From Java 5.0, it is better to use the -agentlib:jdwp single option: 从Java 5.0开始,最好使用-agentlib:jdwp单个选项:

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

Options on -Xrunjdwp or agentlib:jdwp arguments 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) transport=dt_socket :表示用于连接到JVM的方式(socket是一个不错的选择,可用于调试远程计算机)
  • address=8000 : TCP/IP port exposed, to connect from the debugger, address=8000 :暴露的TCP / IP端口,用于从调试器进行连接,
  • suspend=y : if 'y', tell the JVM to wait until debugger is attached to begin execution, otherwise (if 'n'), starts execution right away. suspend=y :如果为“ y”,则告诉JVM等待直到连接了调试器开始执行,否则(如果为“ n”),立即开始执行。

#4楼

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

#5楼

There's a lot of environment problems if you are using Maven. 如果您使用的是Maven,则会有很多环境问题。 So, if you start your program from maven, just run the mvnDebug command in place of mvn and attach a debugger on port 8000. It you take care of all the environment problems. 因此,如果您从maven启动程序,只需运行mvnDebug命令代替mvn并在端口8000上附加调试器即可。它可以解决所有环境问题。


#6楼

Since Java 9.0 JDWP supports only local connections by default. 由于Java 9.0,JDWP默认仅支持本地连接。 http://www.oracle.com/technetwork/java/javase/9-notes-3745703.html#JDK-8041435 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值