JDB - Session


This chapter describes how to start a JDB session in different ways. JDB launch is the frequently used technique to start a JDB session.

There are two different ways to start a JDB session:

  • Starting JDB session by adding class (main class name) to it.
  • Adding JDB to running JVM to start session.

Start a Session by Adding Class

The following command starts a JDB session:


\>jdb <classname>


Let us assume we have a class named TestClass. The following command starts a JDB session from the TestClass.

\>jdb TestClass

If you follow this command, it starts a new Java VM with any specified parameters. Thereafter it loads the class and stops it before executing the first statement of the class.

Start a Session by Adding JDB to a Running JVM

Given below is the syntax and example to start a JDB session by adding the JDB to a running JVM.


The following syntax is for JDB session:



Let us assume the main class name is TestClass and JVM allows the JDB to connect it later. The following is the command to add JDB to JVM:

-agentlib:jdwp=transport=dt_shmem,address=jdbconn,server=y,suspend=n TestClass

Now you can attach the JDB to the JVM with the following command:

\> jdb -attach jdbconn

Note: Here, the TestClass is not added to the JDB command, because JDB is connected to the running VM instead of launching a new one.