Is it possible for my Java program to start a 2nd JVM (via ProcessBuilder for ins开发者_Python百科tance running javaw.exe
) in Debug mode so it appears in Eclipse's debug window?
If so, how?
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
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.
精彩评论