8

Is it possible for my Java program to start a 2nd JVM (via ProcessBuilder for instance running javaw.exe) in Debug mode so it appears in Eclipse's debug window?

If so, how?

Jason S
  • 184,598
  • 164
  • 608
  • 970
  • Possible duplicate of [What are Java command line options to set to allow JVM to be remotely debugged?](http://stackoverflow.com/questions/138511/what-are-java-command-line-options-to-set-to-allow-jvm-to-be-remotely-debugged) – ivan_pozdeev Mar 17 '17 at 07:57
  • NOT A DUPLICATE, please read the whole question. This is an eclipse-specific question. – Jason S Mar 17 '17 at 18:47

2 Answers2

7

A possible way to achieve what you (possibly) want: enable the second jvm for remote debugging. As far as I remember, you can tell the jvm to wait until the remote debugger is hooked to the session. Then, after that "child jvm" is spawned, start a remote debugging session in eclipse.

This is the set of parameters for a classic VM:

java -Xdebug -Xnoagent -Djava.compiler=NONE 
     -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 ...

(suspend=y tells the jvm to wait for the debugger, 5005 is the port in this example)

Starting from JavaSE 1.5, these were replaced with a standardized parameter:

java -agentlib:jdwp=transport=dt_socket,address=localhost:9009,server=y,suspend=y
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
  • more info at: http://www.ibm.com/developerworks/opensource/library/os-eclipse-javadebug/index.html – eee Apr 19 '11 at 14:54
  • Hmm. Well this *almost* works. The issue here is that the JVM will be launched sometime in the future, and I can't tell Eclipse to wait for later. It seems to expect that the JVM in question is available *now*. – Jason S Apr 19 '11 at 15:08
  • @Jason - hmm, it was my understanding that you (1) start the parent application, (2) spawn the child jvm with suspend=y and then (3) start the remote debugging session in eclipse. That doesn't work? – Andreas Dolk Apr 19 '11 at 16:54
  • That works only if I increase timeouts in my client / server apps to the point where I can tolerate the time needed to manually execute step (3) after manually executing step (1). If that's my only choice, I'll deal. I'd rather have step (3) occur automatically somehow. – Jason S Apr 19 '11 at 16:59
  • @JasonS to execute step (3) automatically, Eclipse must be somehow listening for requests to start a debug session so that your app can send one. – ivan_pozdeev Mar 18 '17 at 01:22
3

If you're working on an Eclipse plugin, you could use Eclipse's mechanism for starting a new application, using the DebugUITools, basically

org.eclipse.debug.core.DebugPlugin.launch(configuration, "debug");

I once used this to launch applications in debug mode, and it worked as expected, including full support on breakpoints set within eclipse, variable introspection etc. If this is what you're looking for, you should give it a try.

sschwieb
  • 333
  • 2
  • 5