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:
The following command starts a JDB session:
Let us assume we have a class named TestClass. The following command starts a JDB session from the 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.
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:
\>java -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.