Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProcessBuilder debugging

I created an executable jar and executed it using process builder from another java program. Here's my code -

public class SomeClass {
public static void main(String[] args) {
    Process p = null;
    ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");
    pb.directory(new File("/Users/vivek/servers/azkaban-0.10/TestApp/src"));
    try {
        p = pb.start();
    } catch(Exception ex) {
        ex.printStackTrace();
    }
}

}

I'm trying to now debug the src.jar from eclipse. I provided the project src as external project in my debug configuration, but it still never hits any of my break points. Is there a way to set up a debug environment for something like this?

like image 453
Vivek Rao Avatar asked Feb 09 '12 03:02

Vivek Rao


1 Answers

Ok, so I managed to get this to work. Unfortunately, I cannot find the sample project I used for this, so I'll try to explain the best I can. Consider this line from above -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "src.jar");

All I needed to do was add Xdebug as a parameter to this -

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005", "src.jar");

Then I created a debug environment in eclipse, set the port as 5005 and set a few breakpoints in the jar's source code and it worked!

like image 66
Vivek Rao Avatar answered Sep 18 '22 07:09

Vivek Rao