2

There is a .jar program with a GUI. I want to run it inside my java program and be able to use its buttons (press buttons), compile text fields, select radio buttons, etc.. (always from my java program).

Is this possible?

Maroun
  • 94,125
  • 30
  • 188
  • 241
Marco Micheli
  • 707
  • 3
  • 8
  • 26
  • This might be helpful: http://stackoverflow.com/questions/1320476/execute-another-jar-in-a-java-program – Smajl Apr 27 '13 at 09:04

2 Answers2

2

If you want to include its GUI in your parent program, then include this jar in your classpath and invoke its main program like any other method

if you want it to be executed separately, then you need to execute it like a command-prompt way,

java runtime.getruntime() getting output from executing a command line program

If you want it run separately, but still want data from it, then you need to ensure that you expose its API to external systems (accessible from it) either via RPC or web-service

Community
  • 1
  • 1
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
  • 2
    And this is how you can execute jar file from command line http://stackoverflow.com/questions/5774970/run-jar-file-in-command-prompt – gurvinder372 Apr 27 '13 at 09:08
2
      ProcessBuilder pb = new ProcessBuilder("java", "-Xmx1024m", "-Xms1024m",
             "-DTOOLS_DIR=F://Net Beans Work Space//calc//dist", "-Daoi=whole", 
             "-jar", "F://Net Beans Work Space//calc//dist//calc.jar");

      pb.start();

Use this code it will surely run your jar file what you have to change is the paths in above code please reply it will work for you I will be thankful for you kind reply

Tech Nerd
  • 822
  • 1
  • 13
  • 39
  • 2
    "-DTOOLS_DIR=F://Net Beans Work Space//calc//dist" it means the dist folder of you containing the .jar file (change it for your path) "F://Net Beans Work Space//calc//dist//calc.jar" it means give it the whole complete path of your .jar file I'm waiting for your answer desperately please let me know if it was helpful – Tech Nerd Apr 27 '13 at 10:31