18 Java Stand-alone Applications on z/OS Volume 1
2.2.2 Writing JCL for a Java batch job
Just like any other program written for the mainframe operating environments,
Java batch jobs must be submitted and controlled using JCL scripts. IBM
provides a utility program called BPXBATCH
to run shell scripts and executable
files that reside in the HFS from JCL scripts. Sample JCL to invoke the simple
Java program we discussed in the previous section is in Example 2-3.
Example 2-3 Sample JCL to invoke a Java program
//JAVAP JOB (ITSO),'USER1',REGION=30M,
// CLASS=A,MSGCLASS=X,NOTIFY=&SYSUID
//* ----------------------------------------------------
//* Run Java program
//* ----------------------------------------------------
//RUN EXEC PGM=BPXBATCH,
// PARM='SH java -cp /u/user1/examples Example'
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//STDOUT DD PATH='/u/user1/java.stdout',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHMODE=SIRWXU
//STDERR DD PATH='/u/user1/java.stderr',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// PATHMODE=SIRWXU
//STDENV DD DUMMY
//* ----------------------------------------------------
//* Copy the output of Java program
//* ----------------------------------------------------
//COPYOUT EXEC PGM=IKJEFT01,DYNAMNBR=300,COND=EVEN
//SYSTSPRT DD SYSOUT=*
//HFSOUT DD PATH='/u/user1/java.stdout'
//HFSERR DD PATH='/u/user1/java.stderr'
//STDOUTL DD SYSOUT=*,DCB=(RECFM=VB,LRECL=133,BLKSIZE=137)
//STDERRL DD SYSOUT=*,DCB=(RECFM=VB,LRECL=133,BLKSIZE=137)
//SYSPRINT DD SYSOUT=*
//SYSTSIN DD DATA,DLM='/>'
ocopy indd(HFSOUT) outdd(STDOUTL)
ocopy indd(HFSERR) outdd(STDERRL)
/>
BPXBATCH takes either SH or PGM as a first parameter. When SH is specified,
it expects the name of a shell script to run. When PGM is specified, it expects the
name of an executable file in the HFS. The SH option is the default.
BPXBATCH uses four DD cards: STDOUT, STDIN, STDERR and STDENV.
BPXBATCH directs the standard output of the step to STDOUT, the standard
error to STDERR, the standard input from STDIN, and sets the USS
Chapter 2. Job management 19
environmental variables of the step from STDENV. All of the DD cards are
optional and have the default value of /dev/null. So, if any of the DD cards is not
specified, it is simply ignored by the job.
When STDENV does not set the HOME and LOGNAME variables, they are set
using the logon RACF® profile. When the SH option is used, variables set by
STDENV are overridden by the values specified in /etc/profile, which are
overridden again by the setting in the .profile file in the user’s home directory.
The output of the standard output and error cannot be directly directed to the
SYSPRINT output stream of JCL. Alternatively, in the JCL script, these output
streams should be directed to temporary files (/u/user1/java.stdout and
/u/user1/java.stderr, respectively). Then, the contents of these temporary files
are copied back to the SYSPRINT output stream in the following job step (called
COPYOUT). Consequently, the output of the Java program cannot be examined
until the entire job step is completed. This is a known limitation of the
BPXBATCH utility program.
In the previous example, the environment variables are set using the profile file
of the user who submitted the job before running the specified Java program. If
different settings are required for a job, it is possible to set up the variables in one
of the following three ways:
򐂰 Set the variables in JCL.
//STDENV DD *
PATH=/bin
JAVA_HOME=/usr/lpp/java/J1.4
/*
򐂰 Set the variables in a file in HFS. It must be a text file with read-only access.
The variables should be set as variable=value pairs in the file.
//STDENV DD PATH=’/u/user1/env.profile’,PATHOPTS=ORDONLY
򐂰 Set the variables in a data set. It can be a sequential, PDS, or SYSIN data
set. The variables should be set as variable=value pairs in the data set.
//STDENV DD DSN=USER1.ENV.PROFILE’,DISP=SHR
BPXBATCH is not limited to running batch Java programs; it is able to run any
shell scripts or executable files residing in HFS.
Tip: The contents of temporary files used to store the standard output and
error of Java program in HFS can be examined under USS using tools like
cat, head, and tail while the batch Java program is running (tail -f displays
the last several lines of the file and updates as more lines become available).

Get Java Stand-alone Applications on z/OS, Volume I now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.