Preparing an OSGi application to be called by a CICS program using CICS-MainClass

You can enable a Java main method to be called by a CICS® program by using OSGi configuration. The OSGi application runs in an OSGi JVM server and can be deployed within an OSGi bundle JAR.

Before you begin

Identify the class that contains the main method you want to call.

Procedure

  1. Create a class to contain the main method CICS calls. Creating a class for this purpose is good practice because it keeps the CICS-specific code separate from the rest of your application.
  2. Create a static main method - it must either accept a com.ibm.cics.server.CommAreaHolder or java.lang.String[] argument and return void.
    For example, a main method that receives an array String as it's argument,
    public class CustomerLinkTarget
    {
        public static void main(String[] args)
        {
            // do work here
        }
    }
    For example, a main that receives a COMMAREA,
    public class CustomerLinkTarget
    {
        public static void main(CommAreaHolder cah)
        {
            // do work here
        }
    }
  3. Write the content of the method. The content depends upon what type of link the class is expected to process. A class might receive a commarea to extract data from, or it might need to retrieve data from channels and containers to run any business logic and return data to the calling program.
  4. Create or edit the existing MANIFEST.MF file in the META-INF directory at the projects root.
  5. Add the CICS-MainClass header to the MANIFEST.MF file, with the value equal to the fully qualified name of one or more target classes. The value of the CICS-MainClass can be comma-separated to define multiple classes as program targets.
    For example,
    CICS-MainClass: com.example.App
  6. Optional: Modify the class name by using an alias. Aliases can be used to avoid clashes, compact the class name so that if fits in the JVMCLASS attribute, retain the same JVMCLASS name when a class is renamed, or provide a human-readable name. Aliases are defined in the alias parameter in the CICS-MainClass header.
    For example,
    CICS-MainClass: com.example.App;alias="MyAlias"
    Allows the class com.example.App to be targeted by the JVMCLASS service name of MyAlias.
  7. Build the application.
    • If you are using CICS Explorer® and are connected to z/OS® FTP, you can right-click on the CICS Bundle Project and select Export Bundle to z/OS UNIX file system. CICS Explorer builds and deploys the application. For more information, see Exporting a CICS bundle project to your local file system in the CICS Explorer product documentation.
    • If you are using CICS Explorer, you can right-click on the project in the Project Explorer and select Export > JAR file, creating a JAR file that can be added to a CICS bundle.
    • If you are using build tools such as Gradle or Maven, ensure an OSGi manifest file is created, and the CICS-MainClass header is correctly added to this manifest. You can use the cics-bundle-gradle or cics-bundle-maven plug ins to create and deploy CICS bundles.
  8. Deploy the application. For more information, see Deploying OSGi bundles in a JVM server.

Results

You can now add the OSGi bundle or plug-in project to a CICS bundle and deploy it to zFS. CICS bundles can contain one or more OSGi bundles, they are the unit of deployment for your application in CICS.

Example

Figure 1. OSGi manifest with a CICS-MainClass header for the classes com.example.App and com.example.Target
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Example CICS-MainClass Bundle
Bundle-SymbolicName: com.example
Bundle-Version 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.ibm.cics.server;version="[1.900.0,3.0.0)"
CICS-MainClass: com.example.App,
 com.example.Target

What to do next

Create a PROGRAM definition for each target class, with a JVMCLASS attribute set to the fully qualified name of the target class, as defined in the CICS-MainClass header of the MANIFEST.MF file. PROGRAM definitions can be defined in the CSD file, or in a CICS bundle. The PROGRAM definition can be located in the same CICS bundle as the OSGi bundle part.

For example, a program that is named OSGIAPP targeting the class com.example.App deployed on the JVM server OSGIJVM would be defined:
PROGRAM(OSGIAPP) JVM(YES) JVMSERVER(OSGIJVM) JVMCLASS(com.example.App)
                 API(OPENAPI) CONCURRENCY(REQUIRED) EXECKEY(CICS)

For more information, see PROGRAM resources.