Debugging Java Applications Remotely

This section provides a tutorial example on how to run a Java application and the 'jdb' debugger separately in socket mode. This allows you to debug Java applications remotely.

As we can see from the previous section, we can run a Java application and the 'jdb' debugger separately in shared memory mode. But this requires that the Java application and the 'jdb' debugger must be running on the same machine.

If you have a large application that you need to run a big server machine, you can debug that application by running the 'jdb' debugger on your own desktop machine using the socket debugging communication mode as presented in the previous section.

Let's try it now. Open a command window on a windows system and run:

C:\herong>java -agentlib:jdwp=transport=dt_socket,
   address=localhost:8888,server=y,suspend=y Hello

Listening for transport dt_socket at address: 8888

The target application is launched in "socket server" mode. Its execution is suspended. Now open another command window and run:

C:\herong>jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,

Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
Initializing jdb ...
VM Started: No frames on the current call stack

main[1] stop in Hello.main
Deferring breakpoint Hello.main.
It will be set after the class is loaded.

main[1] cont
> Set deferred breakpoint Hello.main

Breakpoint hit: "thread=main", Hello.main(), line=3 bci=0
3          System.out.println("Hello world!");

main[1] quit

Cool. I know how to run "jdb" to debug an application running on a remote machine now!

However, the command suggested in the JPDA documentation did not work:

C:\herong>jdb -attach localhost:8888 shmemBase_attach failed: The system cannot find
   the file specified

My guess is that the Windows version of "jdb" assumes "shared memory" as the default transport mode.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

'jdb' - The Java Debugger

 'jdb' - Java Debugger Command and Options

 Starting a Debugging Session with 'jdb'

 Debugging Applications with Separate 'jdb' Sessions

Debugging Java Applications Remotely

 Listing Debugging Commands with 'help' Command - Multi-Thread Sample Program

 Starting Debugging Session on a Multi-Thread Application

 Stepping through Statements of a Child Thread

 Checking Variable Values in a Debugging Session

 Debugging the Main Thread of a Multi-Thread Application

 Switching Execution Threads in a Debugging Session

 Suspending Main Thread to Debug Child Thread

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

 'native2ascii' - Native-to-ASCII Encoding Converter

 Outdated Tutorials


 PDF Printing Version