Java Debugging with Netbeans

    Debugging can be quite a wearing experience, especially if it has to be done aidlessly. Nevertheless it is a quintessential technique for Software "bug-fixers". Netbeans offers some good  features which could help in debugging server, applet or command-line processes. Breakpoints, watches, call stack navigation and such additional features help in seeing the code under the hood. This post is a primer on Debugging with Netbeans

     The basic idea of debugging is that there are two processes - one a Serversocket that listens on a specific port and another that attaches itself to that port during the debugging process.Netbeans offers both kinds of sockets  - (i) A "SocketAttach" that attaches to the port  at which  the java process/server process listens to and a (ii) "SocketListen" that listens at the specific port to which another process (say an applet) would attach to.

Steps for Server Process Debugging

This is probably the most widely used form of debugging.

1. Start the server in the debugging mode. (For Glassfish, this is done by setting the debug-enabled flag to true in <DOMAIN-DIR>/config/domains.xml and restarting the server. Note the port no at which the server is listening)

2. In the Netbeans IDE, open the code base which is in sync with the deployed server code.

3. Goto Run-> Attach Debugger -> Choose ServerAttach mode. The NB IDE attaches to the socket opened by the server in this case.

4. Provide details of the server host and port

5. Set breakpoints in the code and launch the application. The thread stops at the breakpoints, and the code could be stepped over or stepped into to debug further.

Steps for Java Command Line Debugging

1. To debug a java command line process, run the command in the debug mode:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=<portNo>,server=y,suspend=y ABCProg

2. Open the code base in Netbeans and Attach the debugger in the SocketAttach mode, provide the host and port information

Steps for Applet Debugging

1. For Applet debugging, go to the Java ControlPanel (In Unix, it is <JAVA_HOME/bin/ControlPanel, in Windows, ControlPanel -> Java). Navigate to the Java tab - View Settings - Edit the Java Runtime settings. Furnish this information:

-agentlib:jdwp=transport=dt_socket,address=<hostName>:<portNo>

This makes the browser JRE open a socket connection while launching the applet.

2. Open the NB code base and attach the debugger in the SocketListen mode by furnishing the host and port information.

 

Happy Debugging!!!

Comments:

supercalifragilisticexpialidocous

Posted by a on November 16, 2008 at 09:55 PM SCT #

i tried this -agentlib:jdwp=transport=dt_socket,address=localhost:90 and when i try to attach the debugger using SocketListen mode i got this message "Listening on 90
Address already in use: JVM_Bind"
Do u have any idea about why this is occurring.

thx for help

Posted by André on April 03, 2009 at 11:40 AM SCT #

<html>

Posted by guest on October 21, 2010 at 07:58 AM SCT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

nitkal

Search

Categories
Archives
« September 2015
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks