Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach debugger to application using Eclipse

Can you attach to a running application using Eclipse, similar to how you attach using Visual Studio?

like image 342
Luchian Grigore Avatar asked Jul 28 '11 07:07

Luchian Grigore


People also ask

How do I debug a program in Eclipse?

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.


1 Answers

Yes.

If you start your server with the debug port open, by adding this into your java command:

-Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n 

And you have the source code in your project (technically this isn't required, but it's kind of useless unless you do), you can connect to the running server by setting up a "debug configuration" with host = the machine the server is running on and port = 8888 (for example - see options above)

You can then set break points and the debug session will halt the server there and you can inspect variables/fields, and even set their values.


Update

The more modern command-line options for the JVM to do this are

 -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:8888,server=y,suspend=n 
like image 148
Bohemian Avatar answered Oct 23 '22 04:10

Bohemian