Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a Java program without using an IDE?

Tags:

java

How do you turn the debug on and off within your Java program ? How do you turn the debug on and off without recomipiling the java program?

like image 690
Abinash Sinha Avatar asked Jul 13 '13 13:07

Abinash Sinha


People also ask

How do I Debug a Java file?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead. Either actions mentioned above creates a new Debug Launch Configuration and uses it to start the Java application.

Which command is used to Debug a Java program?

The debugger is started with the jdb command; it attaches to the JVM using JPDA. The JVM starts up, but suspends execution before it starts the Java application.

Is there a debugger for Java?

The Java Debugger, jdb, is a simple command-line debugger for Java classes. It is a demonstration of the Java Platform Debugger Architecture that provides inspection and debugging of a local or remote Java Virtual Machine.


1 Answers

A setting to the Java virtual machine allows debuggers e.g. jdb to attach. See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html

This is the important bit:

Running MyClass in a JVM with debugging enabled:

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

Using the jdb debugger

jdb -attach jdbconn 

Note: These option settings are for a connection JVM <-> debugger on the local machine via shared memory, other useful settings allow to connect to a JVM on a remote machine via network sockets.

like image 176
mvw Avatar answered Sep 17 '22 15:09

mvw