FaqDebuggingRemote

How to attach NetBeans debugger to a running application?

In order to be able to attach debugger to an application, the JVM have to be running in debugging mode. Also the application should be compiled with -g option passed to javac.

Required options

There are two required options, which need to be passed to a Java program so that another JVM can attach to it and debug it:

-Xdebug
-Xrunjdwp:<JDWP sub-options>

where JDWP sub-options are comma-separated properties. E.g.:

-Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n
  • transport is a method of communication between a debugger and the virtual machine that is being debugged.
  • address when establishing a connection, transport addresses is used to identify the end-point of the connection.
  • server if the server property is 'y', the application will listen for a debugger to attach; otherwise, it will attach to the debugger at the specified address.
  • suspend if suspend is 'n', the application will start immediately and will not wait for a debugger to attach to it. If 'y', the application will be suspended until you attach to it.

Full documentation of options is described in JPDA Connection and Invocation Details document.

If using old JDKs (before JDK 5), you may need to pass -Xnoagent -Djava.compiler=NONE as well.

When dt_socket transport is used, the address property specified the port number. On MS Windows, dt_shmem transport can be used for faster shared-memory communication when both application and debugger are running on the same computer. The the address specifies the name of a shared memory region.

Attaching to the application from NetBeans

  1. From the main menu, select Debug > Attach Debugger... (In NetBeans 6.1 and older select Run > Attach Debugger...).
    (A dialog will appear.)
  2. Make sure that JPDA Debugger is selected in the combo-box.
  3. Select the appropriate connection type (with respect to the value of the " transport " sub-option).
  4. Enter values of other options:
  • If you use " dt_socket " transport:
    Enter the hostname of computer where the debugged application is running (can be "localhost" if it is on the same computer) into the Host field.
    Enter the selected port number into the Port field.
  • If you use " dt_shmem " tranport (only for MS Windows):
    Enter the shared memory name (e.g. "myapp").
  1. Press button OK.



  Applies to: NetBeans 5.x, 6.x
  Platforms: All
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo