Im trying to launch a jar file as a process, the command I need to run is something like this:
"java -Xmx512M -Xms512M -jar myapp.jar args"
And this is the code I currently have working:
ProcessBuilder builder = new ProcessBuilder();
String[] command = {"java", "-jar", "myapp.jar"};
builder.command(command);
Process process = builder.start();
OutputStream stdin = process.getOutputStream();
InputStream stdout = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
ReaderThread rt = new ReaderThread(reader);
Thread handle = new Thread(rt, "ReaderThread");
handle.start();
But if I try to add something like the "-Xmx1024M" I would get a "Maximun heap error" or if I try to add the "args" in the last string then I get "Unable to access jarfile".
So what is the right syntax to add all the paramaters for the system call to be done in the right order?
Thanks a lot for your help.
EDIT:
I also tried passing the whole command but for some reason that didnt work.