Compiling a java Program for CICS – OSGi JVMServer version

By | February 15, 2014

In an earlier post, I discussed compiling java programs for CICS using a batch job.  Unfortunately, starting with CICS TS 5.1 (or in CICS TS 4.2 using a JVM Server), this no longer works.

CICS TS 5.1 did away with the JVM Pool structure and any java applications you have need to be repackaged in OSGi bundles and placed in CICS bundles.  There are instructions for how to do this using eclipse.  And there are instructions for developing new java applications (and servlets, which is new).  So, quick and dirty, I needed a way to compile my existing java program using a batch job.  Compiling the java program is the same, but the job also needs to create the OSGi bundle structure and the CICS bundle structure.  Also, a CICS bundle needs to be defined to CICS, either view the CICS Explorer (eclipse) or CEDA or DFHCSDUP.

So far, I use the sample JVM Server supplied in the DFH$OSGI group, DFH$JVMS.
The CICS bundles are stored in the z/OS HFS at /usr/lpp/cicsts/java/xxx/bundles where “xxx” represents the target CICS environment, development, qa or production. In that directory, you should end up with:

cics-bundle-name/osgi-bundle-symbolic-name.jar 
                /package-name.osgibundle
                /META-INF/cics.xml

The jar should end up with the classes (in appropriate package sub-directories) and a manifest.
The CICS CEDA bundle definition points to /usr/lpp/cicsts/java/xxx/bundles/cics-bundle-name.  The cics.xml lists the osgibundle file(s).  The package-name.osgibundle file relates the osgi-bundle-symbolic-name in the jar manifest.  Confusing.  There is a pretty good diagram in a presentation by Tobias Leicher.

Disclaimer:  This is not well researched and may not be suitable to your environment.  This should be considered a hack at this point.

//*
//* Package a java application into a OSGi bundle
//* Package the OSGi bundle into a CICS bundle
//*
//JAVAC    EXEC PGM=AOPBATCH,REGION=140M,PARM='//bin/sh'
//STDOUT   DD  SYSOUT=*
//STDERR   DD  SYSOUT=*
//SYSPRINT DD  SYSOUT=*
//SYSOUT   DD  SYSOUT=*
//STDIN    DD  *
# CICS Bundle
CICS_BUNDLE="com.example.department.cics.samples"

# OSGi Bundle
OSGi_BUNDLE="stockquote"
OSGi_BUNDLE_SN="com.example.department.cics.stockquote"

# Package name
PKG_NAME="stockquote"

# CICS Main class
MAIN_CLASS="getQuote"

# source directory -- where source code has been placed
SRC_ROOT="/u/xxxxxxxx/src/StockQuote"

# java program to compile (or *.java)
PGM="getQuote.java"

# CICS environment (development, qa, production)
CICSENV="development"

# -- #

# EXAMPLE.COM location for CICS java apps
CICSJAVA="/usr/lpp/cicsts/java"

# Locate java & cics
JAVA_HOME="/usr/lpp/java/J7.0_64"
CICS_HOME="/usr/lpp/cicsts/cicsts51"

# build paths for compiling
DST_PATH="${CICSJAVA}/${CICSENV}/bundles"
JAVAC_CPATH="${DST_PATH}/*:${CICS_HOME}/lib/*"
PATH=${JAVA_HOME}/bin:${PATH}

# -- #

umask 002
export TZ=CST6CDT

mkdir -p -m 775 ${DST_PATH}/${CICS_BUNDLE}/META-INF
cd ${DST_PATH}/${CICS_BUNDLE}
mkdir -p -m 775 ${OSGi_BUNDLE_SN}

javac -classpath ${JAVAC_CPATH} \
  -d ${DST_PATH}/${CICS_BUNDLE}/${OSGi_BUNDLE_SN} \
  ${SRC_ROOT}/${PGM}
if [ $? -ne 0 ]
then
  exit
fi

/bin/iconv -f ibm-1047 -t utf8 <<ZZ >MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ${OSGi_BUNDLE}
Bundle-SymbolicName: ${OSGi_BUNDLE_SN}
Bundle-Version: 1.0.0.0
Bundle-Vendor: EXAMPLE
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: ${PKG_NAME}
Import-Package: com.ibm.cics.server;version="1.401.0"
CICS-MainClass: ${PKG_NAME}.${MAIN_CLASS}
ZZ

jar cvfm ${OSGi_BUNDLE_SN}.jar MANIFEST.MF -C ${OSGi_BUNDLE_SN}/ .
/bin/rm -r ${OSGi_BUNDLE_SN} MANIFEST.MF

# include the OSGi bundle into the CICS bundle

/bin/iconv -f ibm-1047 -t utf8 <<ZZ > ${PKG_NAME}.osgibundle
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<osgibundle symbolicname="${OSGi_BUNDLE_SN}"
  version="1.0.0.0" jvmserver="DFH\$JVMS"/>
ZZ

/bin/iconv -f ibm-1047 -t utf8 <<ZZ > META-INF/cics.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<manifest xmlns="http://www.ibm.com/xmlns/prod/cics/bundle"
  id="${CICS_BUNDLE}"
  bundleMajorVer="1" bundleMinorVer="0" bundleMicroVer="0"
  bundleVersion="1" bundleRelease="0"
  build="GM01-20121114-1544">
  <meta_directives>
      <timestamp>$(/bin/date +"%Y-%m-%dT%H:%M:%S%z")</timestamp>
  </meta_directives>
  <define name="${PKG_NAME}"
    type="http://www.ibm.com/xmlns/prod/cics/bundle/OSGIBUNDLE"
    path="${PKG_NAME}.osgibundle"/>
</manifest>
ZZ
/*

You should be able to put more than one class in a OSGi bundle with more than one CICS-MainClass and more than one OSGi bundle in a CICS bundle. You can see some of this in the IBM supplied samples.

Leave a Reply

Your email address will not be published. Required fields are marked *