Tomcat Remoting Debug设置方法

 
Tomcat中设置远程debug方法


何为远程调试?我们一般调试一个web项目的java代码时,需要将你的tomcat服务器和你的开发工具(比如Jbuilder)集成,或需要工具的一些 插件支持(比如Eclipse下的myclipse),这些方式都是在本地进行,即你的开发工具和tomcat运行在同一台服务器上,如果你的开发工具 和服务器不再一台机器上那就需要实现远程调试功能了。

实现方法:在tomcatcatalina.bat文件中加入下面的设置,当然 SET CATALINA_OPTS 变量应该在使用它之前。这是在tomcat启动时设置一些虚拟机参数,使服务器允许远程连接功能,address=5888表示远程连接的端口号,可以设 置成任意其他不冲突端口。其他的应用服务器比如weblogic也应该可以设置这些参数,有兴趣的可以测试。

SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5888 这样就Ok了,重启动tomcat,可以直接独立启动,而不用在eclipes的插件中启动。打开eclipse中的debug设置窗口,选择 Remote Java Application ,新建一个debug项,输入服务器IP和刚才设置端口号,点ok就可以进入debug状态了。Jbuilder中同样可以设置Remote Java Application

 

 

Example:

<用记事本打开 catalina.bat>

@echo off

if "%OS%" == "Windows_NT" setlocal

rem ---------------------------------------------------------------------------

rem Start/Stop Script for the CATALINA Server

rem

rem Environment Variable Prequisites

rem

rem   CATALINA_HOME   May point at your Catalina "build" directory.

rem

rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions

rem                   of a Catalina installation.  If not present, resolves to

rem                   the same directory that CATALINA_HOME points to.

rem

rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",

rem                   "stop", or "run" command is executed.

rem

rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory

rem                   the JVM should use (java.io.tmpdir).  Defaults to

rem                   %CATALINA_BASE%/temp.

rem

rem   JAVA_HOME       Must point at your Java Development Kit installation.

rem                   Required to run the with the "debug" argument.

rem

rem   JRE_HOME        Must point at your Java Development Kit installation.

rem                   Defaults to JAVA_HOME if empty.

rem

rem   JAVA_OPTS       (Optional) Java runtime options used when the "start",

rem                   "stop", or "run" command is executed.

rem

rem   JSSE_HOME       (Optional) May point at your Java Secure Sockets Extension

rem                   (JSSE) installation, whose JAR files will be added to the

rem                   system class path used to start Tomcat.

rem

rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"

rem                   command is executed. The default is "dt_shmem".

rem

rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"

rem                   command is executed. The default is "jdbconn".

rem

rem $Id: catalina.bat 355227 2005-12-08 21:44:16Z keith $

rem ---------------------------------------------------------------------------

 

rem Guess CATALINA_HOME if not defined

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

set CURRENT_DIR=%cd%

if not "%CATALINA_HOME%" == "" goto gotHome

…….

 

复制粗体的内容放在这个位子即可。之后启动tomcat,再eclipse中设置remote debug.

* 启动后你会看见在console中有一下一段话:

Listening for transport dt_socket at address: 8000

即表示debug 设置成功

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值