Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i run a .jar file in java

Tags:

java

jar

I'm making an update function for my project, it's working great, until i want it to restart, basically I download the new file and replace it with the old one, and then i want to run it again, now for some reason it doesn't wna run, and i don't get any error...

Here is the complete update class: http://dl.dropbox.com/u/38414202/Update.txt

Here is the method i'm using to run my .jar file:

 String currDir = new File("(CoN).jar").getAbsolutePath();
 Process runManager = Runtime.getRuntime().exec("java -jar " + currDir);
like image 646
Olindholm Avatar asked Nov 14 '22 14:11

Olindholm


1 Answers

It's not clear to me, why do you need to run the jar with a call to exec() . Given that you need to run the code in the .jar file from a Java program, you could simply run the main() method as defined in the jar's manifest, and capture its output - wherever that is.

Using exec() is OK when you need to call a program from the underlying operating system, but there are easier ways to do this if both the caller and the callee are Java programs.

Now, if your jar is gonna change dynamically and you need to update your program according to a new jar, there are mechanisms for reloading its contents, for instance take a look ath this other post.

like image 61
Óscar López Avatar answered Nov 16 '22 03:11

Óscar López