RD/z Creating a simple Java project

From CICS Wiki

Jump to: navigation, search

Contents


Articles in the RD/z series:


Overview

This article will guide the reader on how to create a simple Java project targeted for the mainframe.

Creating the project

Select the File open from the Taskbar and select New and Java Project.

Specify the project name and click Finish.

Creating the package

First we create a new package.

Creating the source file

Now we create the source file.

Altering the source code

For the purpose of this example we will use source code that is found the the IBM Redbook "Java Application Development for CICS" (SG24-5275-03). The code is provided here in slightly altered condition so that the reader can copy and paste it into their editor. First delete the sample code that was generated in the source program, then copy and paste the source code below into the editor.

package com.wd.ea.ut;
import java.io.PrintWriter;
import com.ibm.cics.server.*;
 
/**
* The HelloWorld class is our first RD/z application targeted for CICS.
* <p>
* This class will use a few classes provided in the dfjcics jar file.
* <p>
*
* @author      John Smith
* @version     1.0
*/
public class HelloWorld {
 
/**
* Main method will be invoked to create CICS objects and
* print messages to the terminal.
* <p>
*/
public static void main(CommAreaHolder commArea) {
try {
PrintWriter out = getOutputWriter();
Task task = Task.getTask();
out.println();
out.println("----------------------------------------------");
out.println("Hello " + task.getUSERID() + ", welcome to CICS!");
out.println();
out.println("This is program " + task.getProgramName());
out.println();
out.println("Transaction name is " + task.getTransactionName());
out.println();
out.println("CICS region sysid is " + Region.getSYSID());
out.println();
out.println("This region applid is " + Region.getAPPLID());
out.println();
out.println("----------------------------------------------");
} catch (Throwable e) {
System.err.print(e);
}
}
 
/**
* Return the terminal principal facility, or <code>null</code>
* if the transaction is not associated with a terminal.
* <p>
* @return TerminalPrincipalFacility object if it exists, null otherwise.
*/
private static TerminalPrincipalFacility getTerminal() {
Object principalFacility = Task.getTask().getPrincipalFacility();
if (principalFacility instanceof TerminalPrincipalFacility)
return (TerminalPrincipalFacility) principalFacility;
else
return null;
}
 
/**
* Is the transaction associated with a terminal?
*
* @return boolean value of whether terminal primary facility exists or not.
*/
private static boolean haveTerminal() {
return getTerminal() != null;
}
 
/**
* Return a PrintWriter that is either directed at the terminal, if
* we have one, or to <code>System.out</code> if not.
* <p>
* @return PrintWriter object which is either the primary facility or
* the System.out object.
*/
private static PrintWriter getOutputWriter() {
if (haveTerminal())
return   Task.getTask().out;
else
return new PrintWriter(System.out, true);
}
}

Save the source file by clicking CTRL+S .

Fixing the project dependencies

Once the source code is saved the following errors will be identified.

The project dependencies in our case are for Java 1.5 and for the dfjcics.jar file. The first dependency we will set is for the level of Java compilation we want:

The next step is to set the project dependencies to add a reference for the TopANT project. This should resolve the current errors we have in our source code. Click OK on the previous Properties page and right click and select build path on the project.

The errors should now disappear from the source code but might still show up in the Problems pane for a while. This can be ignored for the moment.