Building non-OO applications that interoperate with Java
This section describes building non-OO COBOL applications that interoperate with Java™ using built-in Java interoperability features. Existing COBOL programs that are part of the application can be compiled as usual, though they may need new linking considerations. A utility program called cjbuild is provided to assist with building compiler-generated stub files into a DLL that is needed at run time by the application when executing the "glue code" that facilitates interoperability between COBOL and Java.
About this task
- Compile all user programs in the application. Programs that contain non-OO
COBOL/Java interoperability features (that is, JAVA-CALLABLE
directive, JAVA-SHAREABLE directive, or calls to static Java
methods) must be linked in step 3. However, user programs that do not contain any non-OO COBOL/Java interoperability features can be linked as normal during this
step, unless there is a dependency on programs that must be linked in step 3, in which case linking
for these programs must be delayed until step 3 as well.Note: When a COBOL program in the application contains one or more Java-interoperability constructs, compiler generated COBOL "stub programs" are automatically generated to facilitate interoperability with Java. The COBOL constructs that cause these stub programs to be generated are as follows:
- The
JAVA-CALLABLE
directive, which results in a COBOL native method stub program. - The
JAVA-SHAREABLE
directive, which results in a working-storage initialization stub program, and also in a Java class that provides an interface for accessing all shareable WORKING-STORAGE data items in the COBOL program. CALL
statements with a literal call target of the form 'Java.java-class-name.java-static-method-name', which results in a Java call stub program, one for each unique Java call target.
Any stub files that are produced will be compiled and linked in subsequent steps. For simplicity, it is recommended that all stub files for a single interoperable application be located in the same directory on z/OS UNIX. This means that when building each COBOL program in the interoperable application, the
OUTPATH
suboption of theJAVAIOP
compiler option should specify the same output directory. This directory should then be specified as the argument to the-c/--coboldir
option of cjbuild. - The
- Use the cjbuild utility to build a DLL from all the COBOL native method stub programs,
WORKING-STORAGE initialization stub programs, and Java call
stub programs produced in step 1. A side deck for this DLL will also be generated and will be needed
for linking in step 3.Note: The cjbuild utility also generates several Java source files for classes that are needed by Java applications when calling COBOL native methods or accessing COBOL WORKING-STORAGE memory. The cjbuild utility takes care of building these files.
- Link user COBOL programs. Programs that don’t use non-OO COBOL/Java interoperability features can be linked normally and, if desired, can be linked during step 1, if there are no dependencies on programs that need to be linked in step 3. Programs that use non-OO COBOL/Java interoperability features, however, must be linked with the side deck produced for the DLL built in step 2..
- Compile the user Java parts of the application.
CALL statement (Enterprise COBOL for z/OS® Language Reference)
JAVA-CALLABLE (Enterprise COBOL for z/OS Language Reference)
JAVA-SHAREABLE (Enterprise COBOL for z/OS Language Reference)