Run Java in a batch job

Java™ programs run in a batch job by using the Submit Job (SBMJOB) command. In this mode, the Java Qshell Command Entry display is not available to handle the System.in, System.out, nor System.err streams.

You may redirect these streams to other files. Default handling sends the System.out and System.err streams to a spooled file. The batch job, which results in an input and output exception for read requests from System.in, owns the spooled file. You can redirect System.in, System.out, and System.err within your Java program. You can also use the os400.stdin, os400.stdout, and os400.stderr system properties to redirect System.in, System.out, and System.err.

Note: SBMJOB sets the current working directory (CWD) to the HOME directory that is specified in the user profile.

Example: Running Java in a Batch Job

SBMJOB CMD(JAVA Hello OPTION(*VERBOSE)) CPYENVVAR(*YES)

Running the JAVA command in the previous example spawns a second job. Therefore, the subsystem that the batch job runs in must be capable of running more than one job.

You can verify that your batch job is capable of running more than one job by following these steps:

  1. On the CL command line, enter DSPSBSD(MYSBSD), where MYSBSD is the subsystem description of your batch job.
  2. Choose option 6, Job queue entries.
  3. Look at the Max Active field for your job queue.
Related concepts
Java classes, packages, and directories
Files in the integrated file system
Java file authorities in the integrated file system