Previous Topic Next topic Print topic


Create a Class and Build Your Project

In this step, using the supplied COBOL code, you will create a new COBOL class in your project.
  1. Select the project in the COBOL Explorer view and click File > New > COBOL JVM Class. This opens the New Class dialog box.
  2. Enter the following:
    Field Value
    Source folder HelloJVMworld/src
    Package
    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.
    com.microfocus.example
    Name JVMWorldClass
  3. Click Finish.

    A template COBOL program will display in an editor and the program file will be listed in the example folder you specified as part of the package name.

  4. Copy and paste the following COBOL 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.
  5. Click File > Save . By default Eclipse builds your project automatically. If you haven't configured Eclipse to do this, you can build a project at any time by selecting the project in the COBOL Explorer view and clicking Project > Build Project.
You have now created a COBOL class in your project.
Previous Topic Next topic Print topic