开发者

eclipse: debug programmatically initiated process

I'm programmatically executi开发者_运维知识库ng a java process via another java process in eclipse:

Process process = Runtime.getRuntime().exec(command, envp, dir);

Is there any way to tell eclipse to debug the child process?

Alternatively, I could solve this by chaining multiple launch configurations, ie launch process A, on completion launch process B - provided B could be launched in debug mode.


If you use the "Remote Debug" feature in Eclipse then you can point it at any JVM instance. You just need to make sure that each instance is told to use a unique JDWP port. This is how you'd do it from the command line:

java -Xdebug -Xrunjdwp:transport=dt_socket,address=8998,server=y

So, change the 'address' part to whatever port you want, then you can point Eclipse at that port. Here's some more information:

http://java.dzone.com/articles/how-debug-remote-java-applicat


Add a command line option to the child process as follows:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9999

(you can use a different port number than 9999, it's up to you, but best choose a number above 1024)

Then in Eclipse, create a Debug Configuration of type "Remote Java Application". Set the host as localhost and the port as 9999.

This developerWorks article has plenty of extra information.

EDIT: Incidentally for more flexibility in specifying the command line and environment of your child process, use the java.lang.ProcessBuilder class instead of Runtime.exec(...).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜