简体   繁体   中英

How to run and use a .jar program inside a java program

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?

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

      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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM