Configuration and Deployment

To call COBOL from Java using the CVM, perform the following steps:

  1. Install and correctly configure the ACUCOBOL-GT runtime. Optionally, install AcuBench if the system will also be used for COBOL development.
  2. Install and correctly configure a Java Runtime Environment (JRE) Version 1.4.2 or later. Optionally, install a J2SE Software Developer's Kit (SDK) if the same system will also be used for Java development.
  3. Place the path to the JRE /bin directory in the PATH environment variable. Here is an example:
    PATH =D:/j2sdk1.4.2_04/bin.

    If the ACUCOBOL-GT installation directory is not the current directory, then that directory should also be placed on the path. The runtime path must be correctly configured so that a call to LoadLibrary(wrun32.dll) or loading the shared library libruncbl.so succeeds.

  4. Place the path to CVM.jar in the CLASSPATH environment variable. Also ensure that the class or JAR (Java Archive) file that contains the declaration of main is included in the classpath. For JAR files, include the filenames in the classpath. For class files, include the directory where the class files reside. Here is a Windows example:
    CLASSPATH=d:\cobol7\bin\acuUtilities.jar;d:\cobol7\tools\CVM.jar;c:\cobol7\JavaProject

    For UNIX platforms, use a colon as a delimiter instead of a semicolon.

  5. Add the location of the runtime DLLs and shared libraries to the variable LD_LIBRARY_PATH. For example, on Windows:
    LD_LIBRARY_PATH=C:\Program Files\Acucorp\Acucbl900\AcuGT\bin

    On UNIX or Linux, the shared libraries are located in /AcuGT/lib.

  6. Do one of the following:
    1. Place a copy of the COBOL program to be called in the same directory as the ACUCOBOL-GT runtime. This would be the compiled .acu file that contains the COBOL program.
    2. Pass the fully qualified filename of the COBOL program to be called to the runtime.
    3. Use a configuration variable to identify the location of the COBOL program.
  7. Ensure that all configuration options located in the configuration file are set up correctly. This includes the location of the JRE, preloading the JVM, and the command line that will be passed to the JVM.
  8. The Java class being used to call COBOL must provide a main function such as this:
    public static void main(String[] args)
  9. The Java program calling COBOL must include an import statement that imports the ACUCOBOL-GT Java class that is used. Here is an example:
    import com.acucorp.acucobolgt.*;
  10. The Java program calling COBOL must declare two objects: one of type CVM and one of type CALL_OPTIONS. The following is sample Java code that shows how to call a COBOL program, passing two parameters, using the CVM.class:
    CVM cvm = CVM.GET_INSTANCE(); 
    cvm.setErrorsOut("/tmp/errfile"); 
    cvm.setConfigFile("c:/myproject/config"); 
    cvm.initialize(); 
    
    CALL_OPTIONS co = new CALL_OPTIONS(); 
    co.setOption("debug_method", "1"); 
    
    Object objInt = new Integer(1); 
    Object objString = new String("Test String Parameter"); 
    Object params[] = { 
    objInt, 
    objString 
    }; 
    cvm.callProgram("TestJavaToCobol", params, co); 
    cvm.cancelProgram("TestJavaToCobol"); 
    cvm.shutdown();
  11. The COBOL program being called must provide a Linkage Section that matches the order and type of the Java parameters passed in the Java Object array. This is done by the COBOL programmer. Here is an example of a Linkage Section that does this for the above program:
    linkage section. 
    77 test-integer-parameter usage is signed-int. 
    77 test-string-parameter pic x(21) value spaces.