JAVA学习提高之---- JBOSS远程调试

本文详细介绍了如何在JBoss应用服务器上启用远程调试功能。通过修改启动脚本,设置监听端口,并在Eclipse中建立远程连接,可以方便地进行远程调试。适用于JBoss、WebLogic、Tomcat等多种应用服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. remsetJAVA_OPTS=-Xdebug-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y%JAVA_OPTS%
rem set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%


将该注释去掉(即去掉rem),重新用run.bat启动JBoss即可。


Linux环境:
找到Linux环境下的JBoss启动文件:run.sh
为了保留以前的启动配置,我们作以下操作:

# cp run.sh run-debug.sh
# cp run.conf run-debug.conf
# vi run-debug.sh

查找run.conf,改为run-debug.conf,然后保存run-debug.sh文件

# vi run-debug.conf

查找8787,可以找到:

  1. #JAVA_OPTS="$JAVA_OPTS-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"


把注释去掉

重新启动JBoss即可

#./run-debug.sh


启动之后,JBoss服务器会在8787端口进行侦听。

Eclipse的设置

如果使用Eclipse作为IDE开发环境,可以这样设置:


按照画面所示设置好跟JBoss服务器的连接之后,便可在程序中设置断点,执行画面处理,便会在断点出停住调试了。

附:

Remote Debugging with Eclipse

At 8:22 PM on Nov 1, 2005, Levent Gurses Javalobby Newcomers wrote:
<!-- Synopsis -->

How many times trying to fix a server-side Java problem appeared trivial, but getting to the source of the problem took all the time? A remote debugger attached to a Java application can shorten the defect-discovery times significantly and make the process more enjoyable.

<!-- What is it -->

The Java Debugger

The Java Debugger (jdb) is a dynamic, controlled, assignment-based debugging tool. It helps find and fix bugs in the Java language programs both locally and on the server. To use jdb in a J2EE application server you must first launch it with debugging enabled and attach to the server from the debugger through a JPDA port (Default port is 1044).

The default JPDA options for J2EE servers are as follows:

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

The jdb parameters specify the way debugger will operate. For instance transport=dt_socket instructs the JVM that the debugger connections will be made through a socket while the address=1044 parameter informs it that the port number will be 1044. Similarly, if you substitute suspend=y , the JVM starts in suspended mode and stays suspended until a debugger is attached to it. This may be helpful if you want to start debugging as soon as the JVM starts.


Debugging WebLogic

Debugging WebLogic is no different than debugging any other Java remote application. You need to make sure to launch it with the required debugging arguments and attach a debugger. In the case of WebLogic 8.1, you need to add these arguments to the startup script. WebLogic comes with several launch scripts (*.sh and *.cmd) under BEA_HOME/weblogic81/server/bin.

  1. Locate startWSL.cmd and add the following variable DEBUG_OPTS:
    set DEBUG_OPTS = -Xdebug -Xrunjdwp:transport= dt_socket,address=1044,server=y,suspend=n
    
  2. Next, insert the new variable to the WebLogic startup command, after "%JAVA_HOME%\bin\java" and preferably before the other options.
  3. Your startup script should look like:

    "%JAVA_HOME%\bin\java" %DEBUG_OPTS% %JAVA_VM% %MEM_ARGS% %JAVA_OPTIONS%-Dweblogic.Name=%SERVER_NAME% -Dweblogic.management.username= %WLS_USER%-Dweblogic.management.password= %WLS_PW% -Dweblogic.management.server= %ADMIN_URL%-Dweblogic.ProductionModeEnabled= %PRODUCTION_MODE%-Djava.security.policy= "%WL_HOME%\server\lib\weblogic.policy" weblogic.Server

Debugging JBoss

Same as WebLogic, except that you need to change run.bat/run.sh located under JBOSS_HOME/bin.

Linux users should see something similar to this:

 $ cd /var/jboss4/bin
 $ sh ./run.sh 
 =========================================================================

 JBoss Bootstrap Environment

 JBOSS_HOME: /var/jboss4

 JAVA: /usr/java/j2sdk1.4.2_06/bin/java

 JAVA_OPTS: -server -Xms128m -Xmx128m -Dprogram.name=run.sh

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

 CLASSPATH: /var/jboss4/bin/run.jar:/usr/java/j2sdk1.4.2_06/lib/tools.jar

 =========================================================================

Debugging Tomcat

Again, very much similar to WebLogic and JBoss, except that you need to change catalina.bat/catalina.sh located under TOMCAT_HOME/bin.


Debugger Verification

Now you can launch your application in debug mode. Just to make sure that the server is listening to port 1044 you can run netstat /a. You should see port 1044 in the list of open ports (See Figure 1: List of open ports: netstat -a).

Figure 1 List of open ports: netstat -a


The Eclipse Connection

After making sure WebLogic is listening for incoming connections on port 1044, what is left is to tell Eclipse to connect to this port and you are ready to debug.

  1. In Eclipse, navigate to Run | Debug (See Figure 2: Create new Remote Java Application configuration in Eclipse ).
  2. Select Remote Java Application , on the left column. Click New , on the bottom of the same column.
  3. In the Create configuration screen you'll be prompted to enter some values. Start with a meaningful name. In my case that's WebLogic Instance . For Project, select the Java project that contains the source code you want to debug. Leave Connection Type in default, i.e. Standard (Socket Attach) . For Host , enter localhost. If you want to debug a remote server, enter its hostname or IP address. For port, enter 1044 or the port you defined in your WebLogic startup script.
  4. Click Apply
  5. Make sure WebLogic instance is running in debug mode. In the same screen click Debug . Eclipse should automatically take you to the Debug perspective and you should see a stack trace in the Debug view.
  6. If you are not automatically taken to the Debug perspective, select Window | Open Perspective | Other and then click Debug.

Figure 2 Create new Remote Java Application configuration in Eclipse
<span http://

Eclipse Debug window should automatically pop-up with the stack pointer on your first breakpoint (See Figure 3: Breakpoint hit in Eclipse's debugger ). After that, you can use all the various functions that the debugger has to offer, namely variable assignments, step-into, drop to frame, etc.


Figure 3 Breakpoint hit in Eclipse debugger

 

附件里面分别为两个不同版本JBOSS的远程调试设置文件run.bat

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值