This example shows how to run CL programs from within a Java™ program. In this example, the Java class CallCLPgm runs a CL program.
The CL program uses the Display Java Program (DSPJVAPGM) command to display the program that is associated with the Hello class file. This example assumes that the CL program has been compiled and exists in a library that is called JAVSAMPLIB. The output from the CL program is in the QSYSPRT spooled file.
See call a CL command for an example of how to call a CL command from within a Java program.
Example 1: CallCLPgm class
import java.io.*; public class CallCLPgm { public static void main(String[] args) { try { Process theProcess = Runtime.getRuntime().exec("/QSYS.LIB/JAVSAMPLIB.LIB/DSPJVA.PGM"); } catch(IOException e) { System.err.println("Error on exec() method"); e.printStackTrace(); } } // end main() method } // end class
Example 2: Display Java CL program
PGM DSPJVAPGM CLSF('/QIBM/ProdData/Java400/com/ibm/as400/system/Hello.class') + OUTPUT(*PRINT) ENDPGM
For background information, see Use java.lang.Runtime.exec().