'Java Binary SE execution stucked when running from java code

I want to run external *.jar file for my automation test code. This jar file executable is mocking some api services neeed for my test. I run it in my code using:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "./jarpath/yourjar.jar");
Process p = pb.start();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = "";
while((s = in.readLine()) != null){
    System.out.println(s);
}
int status = p.waitFor();
System.out.println("Exited with status: " + status);

but somehow service is started and doesnt leave function.

After starting jar file in cmd terminal, I can see info: "Started Application", but its stucked in the same line. Maybe this is the reason?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source