Using a File Handler in JVM COBOL

File handling operations within JVM COBOL applications can be performed using the native Micro Focus File Handler or using the Managed File Handler.

The native Micro Focus File Handler is provided by the native run-time System, and the Managed File Handler is provided by the JRE itself.

By default, COBOL JVM project types within Eclipse use the native Micro Focus File Handler: if you view the project properties, you will see a reference to mfcobol.jar, as part of the COBOL JVM Runtime System library, in the Libraries tab of the Java Build Path settings. This jar file is what allows Java to access the native Micro Focus File Handler

There are certain circumstances in which the Micro Focus File Handler cannot be used, and in these situations, Visual COBOL automatically uses the Managed File Handler. For example, when running under environments such as Tomcat, WebSphere, or WebLogic, the JVM run-time system is unable to execute native COBOL code, and therefore the Managed File Handler is automatically used. Another example is when creating managed RunUnits via the RuntimeServices library API and you are accessing external files; again, this situation is not permitted to execute native COBOL code, and so defaults to using the Managed File Handler.

In situations where it is possible to use either File Handler, and you want to use the Managed File Handler, you must remove mfcobol.jar from the project: you do so by removing the COBOL JVM Runtime System library; also ensure that mfcobol.jar is not referenced on the CLASSPATH. Because the COBOL JVM Runtime System library also contained some other .jar files (other than mfcobol.jar) that are still required, you must add those files back into the project: on the Libraries tab, use the Add External Jar option to add the following .jar files: mfcobolrts.jar, mfsqljvm.jar, and mfunit.jar.

Note: These files are located in the bin or bin64 sub-directory of your project installation directory. You must select the bit-specific files for the JRE that the project is targeting.

For users working from the command line, you must similarly ensure that the files mentioned above are correctly included/excluded from the CLASSPATH; for example, to ensure that you exclude mfcobol.jar, you could specify set CLASSPATH=%CLASSPATH:mfcobol.jar=%.

Using the Managed File Handler has some inherent limitations; refer to File Handling Restrictions in Managed COBOL for more information.