I am attempting to spawn a new process with the following code:
String exec = (System.getProperty("user.dir") + "/privateers.jar");
String[] command = {"javaw", "-jar", exec};
final Process process = Runtime.getRuntime().exec(command);
System.out.println("Running " + exec);
System.exit(0);
But for some reason, the process just is not running.
The "Running: " + exec
prints out Running D:\Downloads\mcp\ship\ShipLauncher/privateers.jar
When I go to D:\Downloads\mcp\ship\ShipLauncher/
, there is a valid file names "privateers.jar" and which works absolutely fine when I open it with a bat file:
java -jar privateers.jar
PAUSE
There are absolutely no errors in the console.
Does anyone know the issue here? I cannot seem to find the problem.
Update:
I tried using ProcessBuilder
. but no luck.
String exec = (System.getProperty("user.dir") + java.io.File.separator + "privateers.jar");
String[] command = {"java", "-jar", exec};
ProcessBuilder pb =
new ProcessBuilder(command[0], command[1], command[2]);
progressBar.setValue(100);
System.out.println(pb.command());
pb.start();
//final Process process = Runtime.getRuntime().exec(command);
System.out.println("Running " + exec);