ntakouris
ntakouris

Reputation: 958

Running jar via code- Java

final String dir = "C:\\Users\\theo\\Desktop\\1.6 test\\craftbukkit.jar";
Process proc = Runtime.getRuntime()
    .exec("java -Xmx1024M -jar "+ dir +" -o true PAUSE");

So.I did some research around here but this thing apparently is not working/running the JAR file.

Upvotes: 0

Views: 506

Answers (2)

Henry
Henry

Reputation: 43728

Note the space in the path of the jar. This means, in the command you build up it will be seen as two arguments:

java -Xmx1024M -jar C:\Users\theo\Desktop\1.6 test\craftbukkit.jar -o true PAUSE

Try to quote the path to build a command like this:

java -Xmx1024M -jar "C:\Users\theo\Desktop\1.6 test\craftbukkit.jar" -o true PAUSE

Upvotes: 1

  1. You need to provide the full path to the Java executable, not just 'java'.
  2. Assuming the program in question is well-behaved, you could use reflection to invoke the main method on the jar's main class without starting up a new JVM.

Upvotes: 0

Related Questions