JAVA的远程调试方法汇总

原文地址:http://www.blogjava.net/yongbing/articles/221179.html

 

 

首先,JAVA自身支持调试功能,并提供了一个简单的调试工具--JDB,类似于功能强大的GDB,JDB也是一个字符界面的

调试环境,并支持设置断点,支持线程线级的调试。

JAVA的调试方法如下:
1。首先支持JVM,并设置参数,使之工作在DEBUG模式下,加入参数:-Xdebug -Xrunjdwp,transport=dt_socket,server=y,address=5432,suspend=n,onthrow=java.io.IOException,launch=/sbin/echo
其中,-Xdebug是通知JVM工作在DEBUG模式下,-Xrunjdwp是通知JVM使用(java debug wire protocol)来运行调试环境。该参数同时了一系列的调试选项:
transport指定了调试数据的传送方式,dt_socket是指用SOCKET模式,另有dt_shmem指用共享内存方式,其中,dt_shmem只适用于Windows平台。
server参数是指是否支持在server模式的VM中.
onthrow指明,当产生该类型的Exception时,JVM就会中断下来,进行调式。该参数可选。
launch指明,当JVM被中断下来时,执行的可执行程序。该参数可选
suspend指明,是否在调试客户端建立起来后,再执行JVM。
onuncaught(=y或n)指明出现uncaught exception 后,是否中断JVM的执行.

2。启动调试工具。
最简单的调试工具就是上面提到的JDB,以上述调试用JVM为例,可以用下面的命运行启动JDB:
jdb -connect com.sun.jdi.SocketAttach:port=5432,hostname=192.168.11.213
另外,还有好多的可视化调试工具,如 eclipse,jsawt等等。Eclipses可用 ant debug来建立一个调试方法。



其实就是使用了JDK的JPDA,在启动服务器(Jboss或者Tomcat等)的命令行参数里面加上:
-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

Java远程调试

-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=3999,suspend=n

-XDebug               启用调试。
-Xnoagent             禁用默认sun.tools.debug调试器。
-Djava.compiler=NONE  禁止 JIT 编译器的加载。
-Xrunjdwp             加载JDWP的JPDA参考执行实例。
transport             用于在调试程序和 VM 使用的进程之间通讯。
dt_socket             套接字传输。
dt_shmem              共享内存传输,仅限于 Windows。
server=y/n            VM 是否需要作为调试服务器执行。
address=3999          调试服务器的端口号,客户端用来连接服务器的端口号。
suspend=y/n           是否在调试客户端建立连接之后启动 VM 。

Resin:
RESIN_HOME\bin\httpd.exe -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n

Tomcat:
在catalina.sh/bat 的最上面加上:SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 即可。

Weblogic:
在startWebLogic.bat加上:set JAVA_OPTIONS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

启动App server后,在ide下通过debug remote java application并侦听相应的debug端口

Eclipse Rcp:

java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,suspend=y,server=y,address=8000 -cp F:/rcp/plugins/org.eclipse.equinox.launcher_1.0.0.v20070606.jar org.eclipse.equinox.launcher.Main -application rcp.application -data F:/rcp/workspace -os win32 -ws win32 -arch x86 -nl en_US

-Xdebug -Xnoagent等参数需要放在main class前面

http://dn.codegear.com/cn/article/33654
http://www.eclipsezone.com/eclipse/forums/t53459.html
http://articles.techrepublic.com.com/5100-10878_11-6139512.html
http://www.lifevv.com/tenyo/doc/20070918003423784.html

 

Websphere

1. Configure Websphere application server.

    In administraction console, click Servers->Application servers->server name->Debug service(Right down corner). Check "Enable service at server startup", remain default values for others.

   After this, you need to restart application server. To test if the debug service is started, you can use netstat -a to see if the port you set is now being listened.

2. Configure Eclipse

    Click Run->Debug..->Remote Java Application(in the left tree), then click new. Change the Host, Port to what you have configured in the Websphere application server.

   Don't worry about the current class(used as the debug name), there is no main class actually.

   After configuration, run this debug. This will create a connection with the remote debug service.(You can see it using netstat -a in the remote server)

3. Debug

   Set breakpoint in Eclipse.

   Run your application in the application server and running will pause when break point reached.

Reference:

Websphere administration console help

http://www-128.ibm.com/developerworks/cn/linux/opensource/os-ecbug/

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值