Java Calling JVM COBOL

In the IDE

In order to call JVM COBOL from Java, you need to add the JVM COBOL project to the build path of the Java project and to import any COBOL classes you want to use into your Java sources.

This is an outline of the steps to enable calling JVM COBOL from Java:

  1. In your Eclipse workspace, create a JVM COBOL project for your COBOL program.
  2. In your Eclipse workspace, create a Java project for the calling Java program.
  3. In the Java project, add the JVM COBOL project to the project's Java build path.
  4. Add mfcobol.jar and the JVM COBOL Runtime, mfcobolrts.jar to the project's classpath.

    This ensures proper interoperation of Java code with COBOL types which are not directly mapped to JVM types such as COBOL group items or COBOL numeric types which are longer than four bytes.

  5. In the Java source code, add an import statement to import the COBOL class you want to use or the entire package into your Java source file as follows:
    import com.microfocus.cobol.MyClass

    or

    import com.microfocus.cobol.*
    Note: We recommend that you use the RunUnit class for multi-user environments. See com.microfocus.cobol.runtimeservices for more information.

At the command line

To call JVM COBOL from Java, add any locations that include the JVM COBOL classes or packages being called to the CLASSPATH environment variable.

Also in the Java source code, add an import statement to import just the COBOL class you want to use, or add an import statement to import the entire package into your Java source file:

For a single class:

import com.microfocus.cobol.MyClass

For the entire package:

import com.microfocus.cobol.*