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 a Visual COBOL 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.
    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 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.
    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.