Specifying the Java main class and its arguments
The goal of any Java™ launcher is to run the main() method of some Java class and possibly pass it some arguments. You can supply the Java class name and its arguments to the Java batch launcher in the following ways:
- You can specify the fully qualified main class name and any arguments as the
PARM=
string to the batch launcher program. TheJVMPRCxx
stored procedure defines theJAVACLS=
andARGS=
keyword parameters, which you can use to set the program'sPARM=
string. - You can set the JZOS_MAIN_ARGS environment variable to contain the main class name and arguments.
- The contents of the file pointed to by //MAINARGS can contain the Java class name and arguments. You can change this DD name from
//MAINARGS
to some other name by setting theJZOS_MAINARGS_DD
environment variable.
PARM=
- The contents of the
JZOS_MAIN_ARGS
environment variable - The contents of the file that is pointed to by the
JZOS_MAIN_ARGS_DD
environment variable (MAINARGS
, by default)
The main class name and its arguments are read from one or more of these sources as strings that
are separated by white space characters (space, tab, newline). Use single quotation marks if you
specify multiple arguments. When enclosed in single quotation marks, an argument can include a
newline character if the token spans multiple input lines. However, if an input line ends in a
backslash character, the newline character is not included in the quoted argument. When input is
read from the //MAINARGS
file, trailing spaces are automatically removed, but the
input must not contain line numbers.
You can run an executable JAR file by specifying -jar <jar file name>
in
place of a main class name. This command behaves the same as the -jar
option on the
Java shell command launcher: the MANIFEST
entry is read from the named JAR file to find the main class name.
Supplying arguments to a Java class
// EXEC PROC=JVMPRCxx,JAVACLS=’com.package.MyClass’,
// ARGS=’argument1 -arg2’
//STDENV *
...
//MAINARGS DD *
arg.number.3 ’argument4 with embedded spaces
and newline’ ’argument5 with embedded spaces \
but no newline’
//
This example results in the following values:
- Java main class name = com.package.MyClass
arg[1]
=argument1
arg[2]
=-arg2
arg[3]
=arg.number.3
arg[4]
=argument4 with embedded spaces and newline
arg[5]
=argument5 with embedded spaces but no newline