Eclipse: debugging a software initiated process

I programmatically execute a java process through another Java process in eclipse:

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

Is there a way to tell eclipse to debug a child process?

As an alternative, I could solve this problem by combining several startup configurations, that is, start process A, when starting process B - provided that B can be started in debug mode.

+2
source share
2 answers

If you use the Remote Debugging feature in Eclipse, you can specify it on any JVM instance. You just need to make sure that each instance is prompted to use a unique JDWP port. So you can do it from the command line:

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

So, change the β€œaddress” to whatever port you want, then you can specify Eclipse on that port. Here is some more info:

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

+3
source

Add a command line parameter 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 is up to you, but it is best to choose a number above 1024)

Then, in Eclipse, create a debug configuration such as "Remote Java Application". Set the host as localhost and the port is 9999.

There is a lot of additional information in this developerWorks article.

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

+3
source

Source: https://habr.com/ru/post/947602/


All Articles