Thursday, July 28, 2011

Remote Debugging Java Applications

After my previous article about Remote Debugging .NET Applications using Visual Studio 2010, I was curious to see how Remote Debugging works for Java Applications. This blog post covers Remote Debugging Java Applications using NetBeans 7.0.

The basic concepts of Remote Debugging are the same for .NET and Java but the process of setting up the host and remote computers varies between Visual Studio and NetBeans. Similar to the .NET application used in the previous post, the screen shots correspond to a simple Java application which would popup a MessageDialog on a button click. Get the code here.

Before configuring the host and remote computers, it is vital to understand the Java Platform Debugger Architecture (JPDA). JPDA provides the infrastructure you need to build end-user debugger applications for the Java Platform. It includes the following APIs broken into three layers -

  • Java Debug Interface (JDI), a high-level Java programming language interface including support for remote debugging
  • Java Debug Wire Protocol (JDWP), which defines the format of information and requests transferred between the process being debugged and the debugger front end
  • JVM Tools Interface (JVM TI), which is a low-level native interface that defines the services a JVM provides for tools such debuggers and profilers

Configuring the Remote Computer

Run the Java application using the -Xdebug and -Xrunjdwp options from the command line.

java -Xdebug -Xrunjdwp:transport=dt_socket,address=6000,server=y -jar RemoteDebugging.jar

Here's a description of the options of the java command -

-Xdebug Enables debugging support in the VM
-Xrunjdwp Loads in-process debugging libraries and specifies the kind of connection to be made

The -Xrunjdwp option has several sub options. Here are the descriptions of the ones that are used above -

transport Name of the transport to user in connecting to debugger application
address Transport address for the connection
If server=n, attempt to attach to debugger application at this address
If server=y, listen for a connection at this address
server If y, listen for a debugger application to attach
If n, attach to the debugger application at the specified address

By default the application starts in suspended mode. In suspended mode the application waits for a debugger to attach itself to the server at the specified port before the application starts.

Configuring the Host Computer

The host computer is the system running NetBeans 7.0. Open the code of the application in NetBeans and select "Attach Debugger". Specify the Connector as SocketAttach, the Host as the hostname of the remote system and the Transport and Port as specified above.

Specify the breakpoints in the code and they would hit appropriately. There are two major bottlenecks in Remote Debugging -

  • The code from which the executable was built should be available at the time of debugging
  • Applications cannot be configured for Remote Debugging at runtime. The -Xdebug option must be specified at the instantiation of the application, making debugging live production code difficult

Before I conclude, here's an article from OTN (Oracle Technology Network) on the Java Platform Debugger Architecture. Visit it if you would like a deeper insight into Java Debugging. The schematic of the JPDA is from a weblog, check it out here.


Javin @ Java Enum tutorial said...

Nice post, completely agree Eclipse is just fantastic, its ability to allow remote debugging in eclipse for java development is simply fantastic. I have also blogged my eclipse experience as 10 tips on java debugging with eclipse ,let me know how do you find it.

Android app developers said...

This is one of the classic and good post.I like your blog explanation.This is one of the user friendly post.

jack wilson said...

Thanks for sharing this informative blog..

J2EE Training in Chennai

mathew delport said...

Thanks for sharing such informative article on Java technology. It is most preferred technology among developers to create stunning mobile application fast and easy. It also created massive career opportunity for aspiring professionals. JAVA J2EE Training in Chennai

jhansi joe said...

Java training
Nice blog, here I had an opportunity to learn something new in my interested domain. I have an expectation about your future post so please keep updates.
JAVA Training in Chennai

Shariq Waseem said... @ Movers and packers in Delhi @ Delhi packers and movers

Shariq Waseem said... @ Movers and packers in Delhi @ Delhi packers and movers

Andrew Son said...

The information you have given here are most worthy for me. I have implemented in my training program as well, thanks for sharing.

Hadoop Training Chennai
Hadoop Training in Chennai

Roshini RS said...

I have read your blog, it was good to read & I am getting some useful info's through your blog keep sharing... Informatica is an ETL tools helps to transform your old business leads into new vision. Learn Informatica course in Chennai from corporate professionals with very good experience in informatica tool.
Informatica training in chennai|Informatica courses in Chennai|Informatica institutes in Chennai|SAP training in chennai

Melisa said...

Nice Article! Mostly I have gathered knowledge from the blogger, because its provides more information over the books & here I can get more experienced skills from the professional, thanks for taking your to discussing this topic.
sas training in Chennai|sas course in Chennai|sas training institute in Chennai

varshini devi said...

Wow! It was the best article , actually you have posted something useful than others, because I read many articles related to this basics of programming, but I only get impressed with your post only, keep posting.
ccna course in Chennai|ccna training in Chennai|ccna training institute in Chennai

geethu said...

This article is very interesting about programming.
Best Java Training Institute in Chennai .

Bay Max said...

Excellent post.It was good and quite interesting.Thanks for sharing this valuable post.Keep sharing.

Best Informatica Training in chennai
| Informatica training center in chennai

Nikshitha S said...

The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The python programming language is very popular and most widely used.
Python Training in Chennai | Python Course in Chennai

Naviya Nair said...

I have read your blog its very attractive and impressive. I like it your blog.

.Net Training in Chennai | .Net Online Training | Dot Net Training in Chennai

Dot Net Online Training | LINQ Online Training

Sathya G said...

I have seen that all will say the same thing repeatedly. But in your blog, I had a chance to get some useful and unique information. I would like to suggest your blog in my dude circle.
Software Testing Training in Chennai

Aptron said...

Nice post!! Thanks for sharing. This is informative and really useful for me.

Loadrunner Training Institute in Delhi
Best Magma Training in Delhi
Mobile and Database Training Institutes in Delhi

meenumaga said...

Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Business Tax Return
Cpa Tax Accountant
Tax Return Services

Mathew Stephen said...

Really helpful and I would like to read more about Java. Keep up the good work and continue sharing.
Angularjs Training Chennai | Angularjs courses in Chennai | Angular 4 Training in Chennai

jaya prakash said...

Great.Nice information.It is more useful and knowledgeable. Thanks for sharing keep going on and I expect more blog like this

Cloud Computing Training in Chennai

chenna sankar said...

Nice post!!

Hadoop Training in Chennai

chenna sankar said...

Great information....

VMware Training in Chennai

caroline jesi said...

Technology is in a growing way, if you want to shine your career just try to learn a latest technology skill which is having great scope in future.
Big Data Course in Chennai|Big Data Training Chennai

harry lopiz said...

This article clears my mind. Writer has done great job. Best thing about this blog is its simplicity. Thank you so much. Keep posting