使用ProcessBuilder启动Jar

时间:2012-11-09 19:10:23

标签: java processbuilder

我有一个批处理文件:

@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

如何编写它以开始使用ProcessBuilder?

1 个答案:

答案 0 :(得分:0)

如果你真的想在这里使用ProcessBuilder,那就是:

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

但Runtime.exec()对于这项工作也很好:

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

注意:我们需要“cmd / c start”因为start不是app,它是cmd的命令