you can execute the jar file with in java program.
make sure that you have added Manifest file in the jar which has Main-Class attribute.
My steps and output:
Created manifest file with the following line: Main-Class: com.demo.TestJar
Created Test Java program:
package com.demo; public class TestJar extends Object { public static void main(String args[]) { System.out.println("TestJar"); } }
Package the jar : jar cvfm /home/user/TestJarOne.jar manifest.txt
Write test program:
import java.io.BufferedInputStream; import java.io.IOException; public class TestJSS extends Object { static int i = 0; public static void main(String args[]) throws IOException, InterruptedException { System.out.println("Calling jar"); Process p = Runtime.getRuntime().exec("java -jar /home/user/TestJarOne.jar arg1 arg2"); BufferedInputStream bis = new BufferedInputStream(p.getInputStream()); synchronized (p) { p.waitFor(); } System.out.println(p.exitValue()); int b=0; while((b=bis.read()) >0){ System.out.print((char)b); } System.out.println(""); System.out.println("Called jar"); }
}