Question & Answer
Question
What are the steps you need to take to get log4j working in a simple HelloWorld Java(TM) program running under CICS Transaction Server for z/OS (CICS TS)?
Answer
The way Log4J works is it obtains loggers, which can either be globally shared or customized on a per-class basis, and then using the output from those to generate code to appenders. So you need a way to configure both of these. Typically, this can be done by putting a log4j.properties on the classpath, but you do not have that luxury in an OSGi environment.
As referenced in the IBM Redbook, CICS and the JVM server - Developing and Deploying Java applications, when non-OSGi and OSGI compliant library JAR files such as log4j.jar are required by an application, it is a better OSGi practice to create a library JAR file rather than edit the class path. This can be achieved by using the New > Plug-in from Existing JAR Archives wizard.
The new OSGi bundle created in this way wraps the existing JAR file and exports the packages required by other dependent bundles. The wrapper bundle can then be used by other plug-ins in the Eclipse integrated development environment (IDE) by importing the required packages. The bundle can also be exported as either a CICS bundle or a middleware bundle into the JVM server OSGi framework, allowing the framework to verify the bundle dependencies ahead of time.
When working with CICS and log4j, some clients have bundled a version of log4j within every CICS application bundle. So, each of the log4j files including the log4j.properties file are contained within the CICS bundle itself. For this scenario, the project setup would be as follows:
Project setup:
Log4jBundle project (OSGI bundle)
contains MANIFEST.MF
contains log4j.jar
contains log4j.properties
HelloWorldBundle project (OSGI bundle)
contains MANIFEST.MF
HelloWorldCICSBundle project (CICS bundle)
contains cics.xml
contains Log4jBundle
contains HelloWorldBundle
If HelloWorldCICSBundle exports the log4j packages, any other Bundles that wish to use log4j will need to import them in order to use the log4j in bundle HelloWorldCICSBundle.
However, the best way is to have log4j in its own bundle that is installed with all the other bundles and this bundle contains the log4j properties. As long as each application uses its own named logger then its easy to configure new ones. There are no permissions issues as long as the location that the files are being written to has write access for the CICS region userid. The setup of this scenario would be:
Project setup:
Log4jBundle project (OSGI bundle)
contains MANIFEST.MF
contains log4j.jar
contains log4j.properties
HelloWorldBundle project (OSGI bundle)
contains MANIFEST.MF
Log4jCICSBundle project (CICS bundle)
contains cics.xml
contains Log4jBundle
HelloWorldCICSBundle project (CICS bundle)
contains cics.xml
contains HelloWorldBundle
Note that if the log4j bundle is installed as an OSGI middleware bundle by specifying it on the OSGI_BUNDLES option within the CICS JVM profile, you must then stop and restart the JVM server if you want to update the milddleware bundle with any changes.
You can include a log4j.xml file in the OSGI bundle project the same way as the log4j.properties file.
Product Synonym
CICS/TS CICSTS CICS TS CICS Transaction Server
Was this topic helpful?
Document Information
Modified date:
05 January 2026
UID
dwa1172301