Executing External JARs from a GUI Java Program
To execute external JAR files within a Java Graphical User Interface (GUI) program, the following steps can be taken:
<code class="java">Process proc = Runtime.getRuntime().exec("java -jar A.jar");</code>
<code class="java">InputStream in = proc.getInputStream(); InputStream err = proc.getErrorStream();</code>
<code class="java">BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedReader brErr = new BufferedReader(new InputStreamReader(err));</code>
<code class="java">String line; while ((line = br.readLine()) != null) { // Process and display the output line }</code>
Note: Always ensure that you clean up and terminate the process after it completes execution. This can be done using the proc.waitFor() method to wait for the process to finish and the proc.destroy() method to terminate it if necessary.
The above is the detailed content of How to Execute External JARs from a Java GUI Program?. For more information, please follow other related articles on the PHP Chinese website!