Setting Up the Environment for Java and COBOL

You need a Java run-time system on any machine that is going to execute Java applications. If you are going to develop mixed Java and COBOL applications, you will need either the Java Development Kit (JDK) available from Oracle or a compliant JDK such as the OpenJDK from Adoptium (or for AIX platforms, IBM's Semeru Runtime OpenJDK).

Your COBOL development system currently supports several Java run-time systems.

For Windows environments

Before you start writing COBOL and Java programs which interact, you need to set up the following environment variables for the COBOL and Java run-time systems:

  • PATH

    The jvm.dll file must be available. Do not move jvm.dll to a different location, because it has dependencies on other files shipped as part of the Java run-time system. The location of this file depends on which version of the JDK you are using. To ensure the file and its dependencies are available, add it to the system PATH. For example:

    set path=jdk-install-directory\jre\bin;jdk-install-directory\jre\bin\subdirectory;%path%

    Where subdirectory might be client, classic, hotspot or server.

    If you generate EJBs or Java beans using the Interface Mapping Toolkit, the Java Compiler must be available. To do this, put the bin directory of JDK on the PATH. For example:
    set path=jdk-install-directory\bin;%path%
  • CLASSPATH

    If you have Java programs that call COBOL, you need to provide access to the Java classes that interface to the COBOL run-time system. To do this, ensure that mfcobol.jar is specified by the CLASSPATH environment variable. For example:

    set classpath=install-directory\base\bin\mfcobol.jar;%classpath%;.;

    Alternatively, you can set the classpath when you run a Java program, using the -classpath switch. For example:

    java -classpath ".;install-directory\base\bin\mfcobol.jar;%classpath%" MyClass
    If you generate EJBs or Java beans using the Interface Mapping Toolkit, the tools.jar of the JDK must be on the CLASSPATH. For example:
    set classpath=jdk-install-directory\lib\tools.jar;%classpath%;.;
  • Shared library path

    The operating system's shared library path must include the directory containing libjava. This is often found in a subdirectory of Java's jre/lib directory, although the name of this directory is specific to each platform. On some platforms, you might need to specify more than one directory for this, for example, an additional directory containing the Java native threading support.

For UNIX environments

If you have installed the product to a directory other than the default one, ensure you run the cobsetenv script after installation, as described in this product's installation notes. The script sets or modifies the following environment variables: COBDIR, PATH, CLASSPATH and LD_LIBRARY_PATH (or LIBPATH on AIX). If you did install to the default directory, these variables already point to the correct locations.

The JDK install location must be included on PATH.

To run COBOL and Java together, you need to use the Java/COBOL application launcher, cobjrun, instead of the java or cobrun triggers.

If the JAVA_HOME environment variable is set to the Java install location, then cobjrun uses it in preference to the Java install location which is included on PATH.

Note:
  • On AIX, cobjrun requires that the OS Thread Stack Size is greater than 192k. If this value is lower than 192k, you must execute cobjrun run with the -Xmso192k option - for example, cobjrun -Xmso192k main.

    To check what the OS Thread Stack Size is, executing the following at a terminal: java -verbose:sizes. The OS Thread Stack Size is the number nnn for the "-Xmsonnn" option.

All platforms

If you are developing Java or JVM projects in Eclipse, you do not have to set the Java installation directory using the JAVA_HOME variable. Follow these steps to identify the JRE or JDK using the Properties dialog boxes:
  1. Select your project in the Navigator pane.
  2. On the Project menu, click Properties.

    The Properties for <project-name> dialog box appears.

  3. Select one of the following:
    • For a COBOL JVM project, click Micro Focus > JVM Build Path.
    • For a Java project, click Java Build Path.
  4. Click the Libraries tab.
  5. Select JRE System Library and click Edit.
  6. Select Alternate JRE, click Installed JREs, then select an installed JRE or JDK and click OK.
    Note: Click Add and use the Add JRE wizard to add a JRE or JDK that is not listed.
  7. Click Finish, then click OK.