Execute .jar file from a Java program

vfgjrk picture vfgjrk · Feb 8, 2011 · Viewed 80.7k times · Source

How could I run a local jar file from a java program?

The jar file is not in the class-path of the Java caller program.

Answer

aioobe picture aioobe · Feb 8, 2011

I suggest you use a ProcessBuilder and start a new JVM.

Here is something to get you started:

ProcessBuilder pb = new ProcessBuilder("/path/to/java", "-jar", "your.jar");
pb.directory(new File("preferred/working/directory"));
Process p = pb.start();