开发者

java/Eclipse: starting a new JVM in Debug mode

开发者 https://www.devze.com 2023-02-26 18:26 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消