I want to run a jar script from within a Java program. The command is tested to run without problems if pasted sloley to the Windows cmd.
However, my Java script stucks at p.waitFor()
.
public class MyClass{
public static void main(String[] args) {
try {
// create a new process
System.out.println("Creating Process...");
Process p = Runtime.getRuntime().exec("U:\\locallib\\jdk-8u65-windows-x64\\tools\\bin\\java.exe -Xmx4g -jar U:\\path\\to\\my.jar arg1 arg2");
System.out.println("Process is running...");
p.waitFor();
System.out.println("Process is terminated...");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
Ouput:
Creating Process...
Process is running...
...and nothing else.