An article describing the steps needed to configure Apache Tomcat so that it will be able to execute JVM COBOL code.
The existence of Micro Focus JVM COBOL opens up some
prospects for deploying COBOL into infrastructure that has previously been
tricky to utilise via COBOL. Such a framework is the ubiquitous Apache Tomcat
environment for deploying Java servlets and JSPs. Today it is possible to
create servlets written using JVM COBOL that can deploy to Tomcat. It is also
possible to invoke legacy COBOL applications compiled to JVM COBOL from these
servlets to allow them to integrate with JVM web applications.
The JVM COBOL runtime currently accesses native COBOL by
default. Specific set up requirements exist before JVM COBOL can be deployed to
Tomcat. This document highlights the steps required to deploy JVM COBOL into
Tomcat on Windows and Red Hat Enterprise Linux (though the same steps should
work for all supported Linux and Unix platforms).
Overview
The normal way of deploying support library jars into a web
application is to include the jar files in the WEB-INF/lib directory of the web
application in question. This process does not work for the main JVM COBOL
runtime. JVM COBOL currently utilises the native COBOL runtime for access to
facilities such as file handling (work is in progress to provide a pure JVM
solution). Tomcat will launch any jars within the web applications lib
directory in a class loader specific to that web application instance. When a
native library is loaded in such a class loader it becomes tied to it.
Redeploying the application will use a new class loader and thus the
application can no longer use the native library.
To make the runtime work with Tomcat you must deploy the jar
such that it will load into the system class loader that is the base class
loader for the whole system. The document goes into the steps needed to perform
such a deployment and the environment configuration needed to ensure the
runtime can find the native libraries required.
On Unix there is also a specific issue about the use of
cobjrun that requires additional configuration.
Configuring Tomcat 7 for JVM COBOL on Windows
On Windows the process is relatively simple. You need only
copy the runtime jars into the Tomcat lib directory and launch Tomcat with the
appropriate entries on the PATH variable.
First Time Only
To install Apache Tomcat 7 navigate to http://tomcat.apache.org/download-70.cgi
and select the Windows service installer.
Firstly assume we have a Micro Focus
COBOL install at %COBDIR% (this is usually at C:\Program Files (x86)\Micro
Focus\Visual COBOL 2010 on Windows 7) and an Apache Tomcat install at
%CATALINA_HOME% (usually at C:\Program Files (x86)\Apache Software
Foundation\Tomcat 7.0). In the %COBDIR%\bin directory the JVM COBOL runtime
jars are contained. These are mfcobolrts.jar and mfcobol.jar. Copy these into
%CATALINA_HOME%\lib. This will ensure that Tomcat loads the runtime into the
system class loader and not into one specific to a particular web app.
To launch Tomcat you’ll need to set the
PATH variable correctly. The native runtime and JVM native support libraries
need to be on the PATH variable that Tomcat is launched from. For a 32 bit JVM
these will be in %COBDIR%\bin. For a 64 bit JVM use %COBDIR%\bin64. You’ll need
to stop any tomcat instance currently running and then launch it with the new
environment. To do this from the command line run the following commands:
#set PATH=%PATH%;%COBDIR%\bin;%CATALINA_HOME%\bin
#tomcat7 //SS//
#tomcat7
Now navigate to the web page localhost:8080 and you should see your Tomcat landing page. Any web
application archive using JVM COBOL classes can now be deployed to this Tomcat instance
if it were a normal Java web application.
Configuring Tomcat 7 for JVM COBOL on Red Hat Enterprise Linux
On Linux and Unix platforms the deployment requirements are a
little more complex. To deal with signal handling in JVM COBOL programs they
must be launched in general with the Micro Focus cobjrun trigger into the JVM
runtime. For this reason any Tomcat instance that wishes to use JVM COBOL must
be launched using the cobjrun trigger rather than the normal java trigger.
However this isn’t as simple as renaming cobjrun as java and
putting it on the path. Tomcat uses JAVA_HOME to find the java trigger and the
VM so you need to modify a Java instance specifically for running JVM COBOL on
Tomcat.
First Time Only
Create a copy of your Java 6 install
and we’ll use this to run Tomcat. Download the Tomcat core zip from http://tomcat.apache.org/download-70.cgi and
unpack it.
Assuming your Java copy is at $JAVA_HOME, your Micro Focus COBOL install is at $COBDIR
(usually this is /opt/microfocus/VisualCOBOL) and Tomcat is installed to $CATALINA_HOME
do the following. Move the java trigger to a back up location:
#mv $JAVA_HOME/bin/java $JAVA_HOME/bin/javabu
Next link the appropriate cobjrun trigger to replace the java trigger. For a 32 bit JVM
this would be cobjrun32, for a 64 bit JVM you want cobjrun64. Assuming 32 bit you do
the following:
#ln -s $COBDIR/bin/cobjrun32 $JAVA_HOME/bin/java
Next you need to copy the impure JVM runtime into Tomcat. This requires that both the
JVM runtime jar (mfcobolrts.jar) and JVM native interop jar (mfcobol.jar) are copied
into $CATALINA_HOME/lib
#cp $COBDIR/lib/mfcobolrts.jar $CATALINA_HOME/lib
#cp $COBDIR/lib/mfcobol.jar $CATALINA_HOME/lib
You may need to set up a user profile for the tomcat manager. To do this edit the file
$CATALINA_HOME/conf/tomcat-users.xml and add the following to the tomcat-users node
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui"/>
Assuming you’ve created a modified Java and Tomcat install as
above do the following to launch it with JVM COBOL support.
Add Java and Tomcat to the path
#export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
Setup your COBDIR
#$COBDIR/bin/cobsetenv $COBDIR
Try to use the java trigger as below
#java -version
It should put out version information. If instead it puts out
the error message ’java: Could not load libjvm.so’ it means that the trigger
cannot find the JVM runtime library. This needs to be added to LD_LIBRARY_PATH
(LIBPATH on AIX/HP_UX) for the trigger to work. The exact location of libjvm.so
varies from JVM to JVM. For the 32bit Oracle 1.6.27 VM on Linux the necessary
command is
#JAVA_LIB=$JAVA_HOME/jre/lib/i386/server
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_LIB
To start tomcat run
#startup.sh
Now navigate to the web page localhost:8080 and you should see your Tomcat landing page. Any web
application archive using JVM COBOL classes can now be deployed to this Tomcat instance
if it were a normal Java web application.
To stop tomcat run
#shutdown.sh