Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to write a java program, which can excute a jar file

Status
Not open for further replies.

kai2005

Programmer
Oct 8, 2005
21
DE
hi all,

I have finished a java program, now someone give me an executable jar file with source code, and want integrate this jar file in my java program.

My Idea is I write a JDialog Object as ProgramChooser, which has some some radio button. When someone choosed an item and clicke OK button, then a choosed program will be actived. For example 3 radio buttons: 1) program1 2) program2(for a jar file) 3) program3

when someone choosed 2. radio button and click OK, then run this jar file.

But which java api?


 
If you have the jar file and source code, why execute it ?
I would have thought you could just call whatever code your wanted to by invoking the desired class.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hello sedj,

I am not sure, whether you have understand me.

You should know, I have finished Programm 1, and then was told, that in Programm 1 will an another Programm be integrated.

Now I have two Choices. One is rewrite Programm1 with using the source code of Programm 2. Another Choice is just invoke the jar file of Program 2. And I think the second choice will be simple.

So I want to know, which api I can use to invoke a jar file.
 
I do understand you - I'm just saying I don't thing it is the right thing to do.

In any case, you don't use an API to run an executable jar file - you just execute it using :

java -jar myjar.jar MyMainClass

You can run system command like this :

Code:
Process p = Runtime.getRuntime().exec("java -jar myjar.jar MyMainClass");
p.waitFor();


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
That's what I suggested in the first reply :)

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hello sedj,
Hello stefanwagner,

thank you all for the reply.
It do work now.

The jar file will be actived after the statements
Process p = Runtime.getRuntime().exec("java -jar myjar.jar MyMainClass");
p.waitFor(); executed. But after I close the jar file, I can not direct back to the last Program, that mean, only when I click it on the windows ProgramSymbolBar.

How can it be automaticly reactived without clicking it on SymbolBar.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top