This example demonstrates how the JVM COBOL run-time system uses the Java property file, created using the mfjarprogmap utility, to call a program that was compiled as part of a package. It shows how you can call a .jar file containing a Java property file, directly from COBOL.
program-id myapp. procedure division. display "Hello world from myapp". goback. end program myapp.
program-id caller. 01 p procedure-pointer. 01 runner pic x(10). procedure division. set p to entry "myapp.jar". move "myapp" to runner. call runner. goback. end program caller.
cobol caller.cbl jvmgen; cobol myapp.cbl jvmgen(sub) iloutput(bin) ilnamespace(com.mycompany.desktopapp);
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.
jar cvf myapp.jar -C bin/ .myapp.jar is created in the current directory.
mfjarprogmap -verbose -jar myapp.jar
The mfcobolprogmap.properties file is created and added to myapp.jar.
java callerThe caller.class file runs, then calls myapp.jar, and because that .jar file contains the Java property file, the run-time system uses it to locate the called program in its packaged location. The result is that the Hello world from myapp message is displayed.