Search code examples
javaprocessbuilder

Start Jar with ProcessBuilder


I have a batch file:

@echo off
cd %AppData%\.minecraft
start javaw -Xms1024m -Xmx1024m -Djava.library.path="\bin\natives" -classpath "bin\minecraft.jar;bin\jinput.jar;bin\lwjgl.jar;bin\lwjgl_util.jar" net.minecraft.client.Minecraft Flood2d

How do I write it to start with ProcessBuilder?


Solution

  • If you really want ProcessBuilder here it is:

    File workdir = new File(System.getenv("AppData"));
    Process p = new ProcessBuilder().directory(workdir).command("cmd", "/c", "start", "javaw", "-Xms1024M", ......).start();
    

    but Runtime.exec() is also fine for the job:

    Process p = Runtime.getRuntime().exec("cmd /c start ......", null, workdir);
    

    Note: we need "cmd /c start" because start is not an app, it's a cmd's command