50

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

Lii
  • 11,553
  • 8
  • 64
  • 88
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625

3 Answers3

57

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
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • I'm new to java so don't really understand what 'start your server' means. This is an application running locally. – Luchian Grigore Jul 28 '11 at 08:18
  • Every java JVM is a "server". It's whatever you want to connect to - it must have been started using a java command – Bohemian Jul 28 '11 at 08:46
  • @Luchian, somehow you are starting your java programm, or not? Or does that someone else and it is already running? Add the rlevant options Bohemian proposed to the "java.exe" command line. – Angel O'Sphere Jul 28 '11 at 10:51
  • 3
    "More modern" means J2SE 5.0+ (JDK 1.5+) http://javahowto.blogspot.com.au/2010/09/java-agentlibjdwp-for-attaching.html – Oliver Bock Nov 04 '14 at 03:07
33

The Debug Configurations panel has a menu item Remote Java Application:

enter image description here

emallove
  • 1,417
  • 1
  • 17
  • 22
-3

How about just do this:

"Open the DDMS perspective, select the device and attach to your app's process (you will see the package name listed)"

.. thanks to this post: https://stackoverflow.com/a/10074263/2162226

Community
  • 1
  • 1
Gene Bo
  • 11,284
  • 8
  • 90
  • 137