Saturday, December 11, 2010

Using Remote Debugging in JDeveloper 11g

The debuggee is the application being debugged which can be running on either a local or remote machine. Doing remote debugging, it means that you can use the debugger to debug code that has already been deployed on a remote machine or running in a different VM instance.

JDeveloper IDE supports both local debugging and remote debugging. For local debugging, JDeveloper automatically launches the debuggee and then attaches the debugger to that program. In remote debugging, you must manually launch debuggee. If you're remote debugging a JSP or a servlet, you must manually start a browser to invoke your JSP or servlet. Once the debuggee is launched and the JDeveloper debugger is attached to it, remote debugging is very similar to local debugging.

Usually, the debugger attaches to the debuggee. It is also possible that the debugger listens and the debuggee attaches to the debugger. In this article, we will show you how to set up and use a Jdeveloper to do remote debugging of applications deployed to WebLogic server (WLS).

Configuring the Remote WLS

To debug an application deployed to the WLS, you first make sure that WLS server is running using the following extra Java options:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=@{debug.port}

When WLS starts, it opens up @{debug.port} (e.g., 4000) and default port is 8453.

Configuring the JDeveloper

Assume you have deployed your application to the remote WLS server. Now let's setup JDeveloper to do the remote debugging. Follow the steps below:
  1. Open the JDeveloper
  2. Go to Tools -> Preferences -> Debugger -> Breakpoints -> Choose Global (Radio box)

    By selecting Global, it means that breakpoints set next are active whenever you are debugging, regardless of what project you are using.

  3. Open the source codes. Set the break points as needed
  4. Right click your project and select Project Properties -> Run/Debug/Profile
  5. Select Default Run Configurations and Edit it
  6. Click on Remote Debugging and Profiling check box in Launch Settings option
  7. Go to Debugger -> Remote Options. Update the following properties:
    • Protocol = Attach to JPDA
    • Host = Host of the Remote server
    • Port = Debug Port number (eg: 4000)
    For remote debugging, you must choose which protocol to use before you start your remote debugging session. We select "Attach to JPDA" because you will be using Java Platform Debugger Architecture (JPDA) and you would like the debugger to attach to the debug process.
  8. Right click on your project -> Click on Start Remote Debugger
  9. A dialog will pop up and make sure your configurations are correct
  10. Activate your application deployed on the remote WLS server via some mechanisms. This should trigger the break points that you have set in JDeveloper.
Java Platform Debugger Architecture (JPDA)

JPDA stands for Java Platform Debugger Architecture. It’s a multi-layered debugging architecture which enables a tool developer such as Oracle JDeveloper to easily and effectively develop a debugger application which will run across platforms, virtual machine (VM) implementations and JDK versions. For more information, see the references.

Summary

You can use JDeveloper IDE to remote debug Java programs, JSPs, servlets, or distributed applications. For debugging Web pages such as JSPs or servlets, you can also use its HTTP Analyzer.


References
  1. JPDA Tutorial by Preetam
  2. Handy JDeveloper utility: the Http Analyzer
  3. Oracle JDeveloper Downloads
  4. Oracle Weblogic Documentation Library
  5. Running and Debugging Java Programs
  6. Remote Debugging with OC4J

3 comments:

KorshaK said...

Hi Stanley ! Thank you for very usefull post! I would like ask you(may be you know) : what option in weblogic server administration console ->Servers(I click on my AdminServer)->Debug tab should I check for proper debuging? Where a lot of them :) I suppose then I check them the server adds in WSL start script proper options for debug (yuo mentioned about them in your blog) BR,Viacheslav

buddy said...

Nice article ,Remote Debugging was the single most feature which is very useful while developing larget enterprise application, specially
if your applicaiton is live and you don't have proper development environment setup in your dev box.

Thanks
Javin
How to setup remote debugging in Eclipse

Author said...

Thanks for the instructions.

I need to debug my app but I get this instead

...........................................................................................Debugger unable to connect to remote process.

Any pointers ?