Run a jar File from java program -


i trying execute jar files java program. using following code :

      try {           runtime runtime = runtime.getruntime();           runtime.exec("path upto jar");       } catch (exception ex) {           joptionpane.showmessagedialog(null, "exception occured" + ex);       } 

but not working. tried google , gave me examples using processbuilder, not working either.

using processbuilder(java.lang.processbuilder) solve problem. syntax follows -

processbuilder pb = new processbuilder("java", "-jar", "absolute path upto jar"); process p = pb.start(); 

you can redirent input/output/error to/from files follows

file commands = new file("absolute path inputs file"); file dirout = new file("absolute path outputs file"); file direrr = new file("absolute path error file");  dirprocess.redirectinput(commands); dirprocess.redirectoutput(dirout); dirprocess.redirecterror(direrr); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -