Previous Topic Next topic Print topic


Example 1: Locating the Java Property File on the CLASSPATH

This example demonstrates how the JVM COBOL run-time system uses a Java property file, created using the mfjarprogmap utility, to call a program that was compiled as part of a package. This example uses the CLASSPATH in order to locate the Java property file.

Note: The following example is designed to be run from an Enterprise Developer command prompt.
  1. Copy and paste the following code into a new file, and save it as myapp.cbl.
            program-id myapp.
            procedure division.
            display "Hello world from myapp".
            goback.
            end program myapp.
  2. Create a trigger program to call the previous program: copy and paste the following code into a new file, and save it as caller.cbl.
            program-id caller.
            procedure division.
            call "myapp".
            goback.
            end program caller.
  3. Create a sub-directory in which to compile the source, and in which the Java property file will be created.
    mkdir bin
  4. Compile the source and trigger programs.

    Windows:

    cobol caller.cbl jvmgen;
    cobol myapp.cbl jvmgen(sub) iloutput(bin) ilnamespace(com.mycompany.desktopapp);

    UNIX:

    cob -j caller.cbl
    cob myapp.cbl -C 'jvmgen(sub)' -C 'iloutput(bin)' 
                  -C 'ilnamespace(com.mycompany.desktopapp)'
    A caller.class file is created in your current directory, and the myapp.class file is created in the bin\com\mycompany\desktopapp (Windows), bin/com/mycompany/desktopapp (UNIX) directory.
  5. Create the Java property file that the run-time system requires in order to locate myapp.class.
    mfjarprogmap -verbose -directory bin
    The mfcobolprogmap.properties file is created in the bin directory.
  6. Create a .jar file that contains the contents of the bin directory.
    jar cvf myapp.jar -C bin/ .
    myapp.jar is created in the current directory.
  7. Run the caller.class file, specifying myapp.jar on the CLASSPATH.

    Windows:

    java -classpath myapp.jar;.;%CLASSPATH% caller

    UNIX:

    java -classpath myapp.jar:.:$CLASSPATH caller
    The run-time system uses the Java property file within the .jar file to locate the program being called by caller.class, which results in the Hello world from myapp message being displayed.
    Note: On Windows platforms, if your CLASSPATH environment variable contains spacey file locations, you may need to enclose %CLASSPATH% in quotation marks.
Previous Topic Next topic Print topic