Quantcast
Channel: Visual COBOL
Viewing all articles
Browse latest Browse all 5819

Wiki Page: Building JVM COBOL Web Service Applications from a Build Infrastructure

$
0
0
Introduction In the Visual COBOL 2.2 - JSP Web Services Tutorial [2] we created a JSP Web Service Application using JVM COBOL and Java in Visual COBOL for Eclipse. If you want to build the application outside of Eclipse as part of a larger automated build infrastructure, then this article shows how to use ant to build the complete application ready to be deployed.   One of the advantages of using ant is the XML file used to control the build process can be the same for Windows and UNIX. The COBOL projects created by Eclipse use ant under the covers and by re-using this, you get the build of your COBOL code for free with no need to maintain a separate set of batch, shell or make files.   Ant also contains tasks which make building the rest of the application straight forward, compiling the Java source code and creating the W eb application AR chive file or WAR for short.   This article provides a template build.xml which can be adapted for similar shaped Web Service Applications involving JVM COBOL.   Some familiarity with ant is assumed. See the reference section for more information on ant [1]. Build.xml This article walks you through creating an ant build.xml. The build.xml file will build a COBOL project and Java source code, and then combine them, plus any additional files, into a WAR file.   If you want to work with the build.xml in Eclipse then we recommend adding it to the Java project. The rest of the article assumes it has been added to the JSPBookDemo project. Building the JVM COBOL Project Many customers have already asked how to build the . cobolBuild ant file which is created when an Eclipse COBOL project is created[ 3].   For our purposes we want to have ant call this as part of our overall build.xml file. This is done simply by using the ant task.   property name= "COBOLProject" value= "" / target name= "buildCOBOL" ant antfile= ".cobolBuild" dir= "${COBOLProject}" / /target The Property COBOLProject can be hard coded into the file or set via the command line.   Because the . cobolBuild XML file contains Micro Focus custom ant tasks the Micro Focus ant libraries which provide the functionality for these task need to be made available to ant. This is a fragment of the command line.   ant - lib "%COBDIR%\bin\mfant.jar" - lib "%COBDIR%\bin\ant- contrib -1.0b3.jar" - DCOBOLProject =..\ CobolBook Command Line This example command line specifies the Micro Focus custom ant task libraries, setting up the COBOL project name, specifying the war file name and an application server specific directory for jar files which are needed for the servlet or other APIs.   It is assumed that it is executed in the Java Project directory and hence the COBOL Project contains a relative path. Ant looks for a default of build.xml. If you wish to call the ant file something else then use the ant –f option to specify the XML file.   Execute from a Visual COBOL prompt on Windows or run $COBDIR/bin/ cobsetenv on UNIX. Make sure ant is on your PATH.   ant - lib "%COBDIR%\bin\mfant.jar" - lib "%COBDIR%\bin\ant- contrib -1.0b3.jar" - Dappservercp = application server libraries directory - DCOBOLProject =..\ CobolBook - Dappname = JSPBookDemo Ant will search CLASSPATH for anything it needs, so one could also specify the jars on the CLASSPATH. Building the Java Source Code The Java ant task javac is used to build the Java source code. It has the advantage that you can just point it at the package directory structure and it works out the rest.   The path element allows the build up of the required CLASSPATH for the javac task. This includes specifying the location of the JVM COBOL class files as well as the application server API libraries.   path id= "appclasspath" fileset dir= "${appservercp}" include name= "**/*.jar" / /fileset pathelement path= "${COBOLProject}/bin" / /path target name= "buildJava" depends= "buildCOBOL" javac srcdir= "${JAVAProject}/src" classpathref= "appclasspath" / /target Building the WAR File The architecture of a war file can be found from the application server documentation [4] and additional requirements may be required depending on application server. It is easy enough to update this task to include additional files.   To build the deployment WAR file and include all the classes from the various projects plus additional configuration files the war ant task is used.   target name= "buildWar" depends= "init,buildJava,buildCOBOL" war destfile= "${appname}.war" webXML= "${JAVAProject}/WebContent/WEB-INF/web.XML" classes dir= "${JAVAProject}/${JAVAclasses}" include name= "**/*.class" / include name= "**/*.properties" / /classes classes dir= "${COBOLProject}/${COBOLclasses}" include name= "**/*.class" / include name=" **/*.cbldat" / include name= "**/*.properties" / /classes lib dir= "${COBDIR}/${libdir}" include name= "**/mfcobol.jar" / include name= "**/mfcobolrts.jar" / include name= "**/mfsqljvm.jar" / /lib fileset dir= "${JAVAProject}/WebContent" include name= "**/*.jsp" / /fileset /war /target classes denotes the WAR classes directory, lib denotes the WAR lib directory and fileset includes files at the top level.   Also of note is the inclusion of the MF JVM COBOL Runtime System. If you don’t use SQL, you can remove this line                   include name= "**/mfsqljvm.jar" / Deployment See your web server documentation for the vendor specific deployment steps. Deployment tools are usually made available or auto-deploy directories you can copy war files straight into. The Complete Build.XML All these elements have been combined to form a complete ant XML file. The additional elements take settings from the environment and configure items which are OS specific.   The first target to be executed by and is specified in the attribute default= " buildWar " . Then there is a small depends chain which makes sure the target nodes get executed in the correct order.  If you want to add new ones make sure they are chained together properly.   Properties can be given specific values and overridden from the command line using – Dproperty -name=property-value.   project name= "WebApp" default= "buildWar" basedir= "." !-- ****************************** -- !-- * Initialisation * -- !-- ****************************** -- target name= "init" depends= "os.init,os.init.windows,os.init.unix" !-- Properties from the environment -- property environment= "env" / property name= "COBDIR" value= "${env.COBDIR}" / !-- Application Server specific libraries -- property name= "appservercp" value= "" / !-- Name of war file -- property name= "appname" value= "JSPBookDemo" / !-- Project directores -- property name= "COBOLProject" value= "" / property name= "JAVAProject" value= "${basedir}" / !-- Location of class files in each project directory -- property name= "COBOLclasses" value= "bin" / property name= "JAVAclasses" value= "build/classes" / /target !-- ****************************** -- !-- * OS-specific initialisation * -- !-- ****************************** -- target name= "os.init" condition property= "windows" os family= "windows" / /condition condition property= "unix" os family= "unix" / /condition /target target name= "os.init.windows" if= "windows" property name= "libdir" value= "bin" / /target target name= "os.init.unix" if= "unix" property name= "libdir" value= "lib" / /target !-- ****************************** -- !-- * Build COBOL Project * -- !-- ****************************** -- target name= "buildCOBOL" ant antfile= ".cobolBuild" dir= "${COBOLProject}" / /target !-- ****************************** -- !-- * Build Java Source code * -- !-- ****************************** -- path id= "appclasspath" fileset dir= "${appservercp}" include name= "**/*.jar" / /fileset pathelement path= "${COBOLProject}/bin" / /path target name= "buildJava" depends= "buildCOBOL" javac srcdir= "${JAVAProject}/src" classpathref= "appclasspath" / /target !-- ****************************** -- !-- * Build War file * -- !-- ****************************** -- target name= "buildWar" depends= "init,buildJava,buildCOBOL" war destfile= "${appname}.war" webxml= "${JAVAProject}/WebContent/WEB-INF/web.xml" classes dir= "${JAVAProject}/${JAVAclasses}" include name= "**/*.class" / include name= "**/*.properties" / /classes classes dir= "${COBOLProject}/${COBOLclasses}" include name= "**/*.class" / include name= "**/*.cbldat" / include name= "**/*.properties" / /classes lib dir= "${COBDIR}/${libdir}" include name= "**/mfcobol.jar" / include name= "**/mfcobolrts.jar" / include name= "**/mfsqljvm.jar" / /lib fileset dir= "${JAVAProject}/WebContent" include name= "**/*.jsp" / /fileset /war /target /project Conclusion The . cobolBuild ant file which is created when any Visual COBOL for Eclipse COBOL project is created can easily be integrated into a build infrastructure which does not require the Eclipse IDE. This means you don’t need to worry about trying to replicate and deal with the subtleties of the class structure of a JVM COBOL project. Other ant tasks are easy to use and this build.XML can be scaled up to include additional projects in the workspace. References 1. Apache Ant Manual 2. Visual COBOL 2.2 JSP Web Services Tutorial 3. Build JVM COBOL by ant 4. War Directory Structure (Oracle WebLogic )

Viewing all articles
Browse latest Browse all 5819

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>