Create a Class and Build Your Project

Now that you have created a project, you need to provide the COBOL code for the application in a new COBOL class. To do this:
  1. Select the project in the Application Explorer view, and then click File > New > Other.
  2. Expand Micro Focus COBOL, and then click COBOL JVM Class.
  3. Click Next. This opens the New COBOL JVM Class dialog box.
  4. Enter the following details:
    Field Value
    Source folder HelloJVMworld/src
    Package* com.microfocus.example
    Name JVMWorldClass
    Note: * A Java package is a mechanism for organizing Java classes, interfaces, and types into namespaces. These entities are stored in a directory structure specified by its package name. In this case, the value "com.microfocus.example" creates the structure <source folder>\com\microfocus\example (Windows) or <source folder>/com/microfocus/example (UNIX).
  5. Click Finish.

    This creates a new COBOL program from the supplied templates to hold the code for the class in the src > com > microfocus > example folder in your project. The program also opens in the editor.

  6. Copy and paste the following code into the editor, overwriting the existing text:
          $set ilusing(com.microfocus.example)
           class-id com.microfocus.example.JVMWorldClass public.
    
           working-storage section.
    
    
           method-id main static.
    
           01 class1 type JVMWorldClass.
          
           procedure division using by value args as String occurs any.
               set class1 to new JVMWorldClass
               invoke class1::instanceMethod
               stop run.
           end method.
    
    
           method-id instanceMethod.
           
           procedure division.
               display "Hello world".
               goback.
           end method.
           
           end class.
  7. Click File > Save . By default, Eclipse is configured to build projects automatically. If this option has been changed, to manually start a build, select the project in the Application Explorer view and click Project > Build Project.