I’m writing a Minecraft server wrapper, and so part of that involves starting the minecraft process via my webapp. The minecraft command line looks like this:
java -Xmx1024M -Xms1024M -jar /path/to/minecraft.jar nogui
Unfortunately I’m having problems dealing with the case where the path to the jar file contains spaces. If I surround the path with “double quotes” then it works on windows, but fails on OSX. If I escape the spaces with backslashes (eg. “C:/Program\ Files/foo.jar”) then it works on OSX but fails on windows. In both cases it fails because it’s splitting the path in half on the space.
Annoyingly, both methods work just fine if they’re actually pasted into a command prompt, it’s just via ProcessBuilder that they cause issues. And it doesn’t make a difference if I use the ProcessBuilder(List) constructor or the ProcessBuilder(String…) constructor.
Does anyone know what’s going on here? Is there a single ‘proper’ way to pass a path with spaces to the command line via ProcessBuilder?
Thanks.