java jpda 远程调试

Java Platform Debugger Architecture(JPDA:Java平台调试架构) 由Java虚拟机后端和调试平台前端组成

对 执行java 或者java -jar 进行远程调试

添加 -agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n 即可

  • 注意一 transport=dt_socket 不可随意更改
  • 注意二 address 是端口,不是ip地址或者host地址

例子 java MainClass ,这里MainClass是要运行的class名字包括包名称

“C:\Program Files\Java\jdk1.6.0_45\bin\java.exe” \
-agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n \
-classpath .;”\E:\V1.0_ZJ\webmodel\otcp\cif\src\conf” \
“-Djava.ext.dirs=\E:\V1.0_ZJ\webmodel\otcp\cif\src\lib” MainClass
rem Listening for transport dt_socket at address: 9000
rem jpda program started

Tomcat 远程调试

不改文件进行远程调试,可以通过命令”catalia.bat jpda start”,用调试状态启动tomcat,


linux则是"./catalia.sh jpda start"。看catalia.bat 和 catalia.sh的区别,大致相同jpda参数是   

JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"   
                command is executed. The default is "dt_socket".   

JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"   
                command is executed. The default is 8000.   

JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"   
                command is executed. Specifies whether JVM should suspend   
                execution immediately after startup. Default is "n".

这里默认的jpda端口号为8000

E:\GIT\apache-tomcat-6.0.44\bin>start “Tomcat” “D:\Program Files\Java\jdk1.8.0_51\bin\java.exe” \
-Djava.util.logging.config.file=”E:\GIT\apache-tomcat-6.0.44\conf\logging.properties” \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n \
-Djava.endorsed.dirs=”E:\GIT\apache-tomcat-6.0.44\endorsed” \
-classpath “E:\GIT\apache-tomcat-6.0.44\bin\bootstrap.jar” \
-Dcatalina.base=”E:\GIT\apache-tomcat-6.0.44”
-Dcatalina.home=”E:\GIT\apache-tomcat-6.0.44” \
-Djava.io.tmpdir=”E:\GIT\apache-tomcat-6.0.44\temp” \
org.apache.catalina.startup.Bootstrap start

Sun 官方文档说明

DESCRIPTION

The Java Debugger, jdb, is a simple command-line debugger for Java classes. It is a demonstration of the Java Platform Debugger Architecture that provides inspection and debugging of a local or remote Java Virtual Machine.

Starting a jdb Session

There are many ways to start a jdb session. The most frequently used way is to have jdb launch a new Java Virtual Machine (VM) with the main class of the application to be debugged. This is done by substituting the command jdb for java in the command line. For example, if your application’s main class is MyClass, you use the following command to debug it under JDB:

C:> jdb MyClass

When started this way, jdb invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class’s first instruction.

Another way to use jdb is by attaching it to a Java VM that is already running. A VM that is to be debugged with jdb must be started with the following options. These options load in-process debugging libraries and specify the kind of connection to be made.

-agentlib:jdwp=transport=dt_shmem,server=y,suspend=n

For example, the following command will run the MyClass application, and allow jdb to connect to it at a later time.

C:> java -agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n MyClass

You can then attach jdb to the VM with the following commmand:

C:> jdb -attach jdbconn

Note that “MyClass” is not specified in the jdb command line in this case because jdb is connecting to an existing VM instead of launching a new one.

There are many other ways to connect the debugger to a VM, and all of them are supported by jdb. The Java Platform Debugger Architecture has additional documentation on these connection options. For information on starting a J2SE 1.4.2 or early VM for use with jdb see 1.4.2 documentation

文章目录
  1. 1. Java Platform Debugger Architecture(JPDA:Java平台调试架构) 由Java虚拟机后端和调试平台前端组成
  2. 2. 对 执行java 或者java -jar 进行远程调试
    1. 2.1. 添加 -agentlib:jdwp=transport=dt_socket,address=9000,server=y,suspend=n 即可
  3. 3. Tomcat 远程调试
  4. 4. Sun 官方文档说明
    1. 4.1. DESCRIPTION
    2. 4.2. Starting a jdb Session