In this earlier blog post, you saw how the CICS build toolkit can be used to automate the build of your CICS projects, including Java dependencies. You can download the CICS Build Toolkit here. But what if you want to use Maven to build your Java? Perhaps you’ve got a Java application you’re already building with Maven, and want to move it to CICS. Or maybe you just want to take advantage of Maven’s automated dependency management for your CICS projects. This blog post will explain how you can use the CICS build toolkit and Maven together.

As an example, I’ll describe how to create a build for the GENAPP extension for Liberty, available from this web page. To follow along with the example, you can use Eclipse for Java EE developers with the following plugins installed:

  • IBM CICS Explorer, including these features:
    • IBM CICS SDK for Java
    • IBM CICS SDK for Servlet and JSP support
  • Websphere Developer Tools for Liberty (WDT), which from CICS Explorer 5.3 is included when you install the IBM CICS SDK for Servlet and JSP support feature
  • m2e plugins for Maven

I’ll assume you’re already familiar with Maven and CICS Explorer.

Setting up Maven

First of all you should configure Maven to look at the Maven repository provided by Liberty. Also define the cicsbt.dir variable, which you should set to the location of the CICS build toolkit on your system. Add the following to your Maven user or global settings e.g. /home/mattwil/.m2/settings.xml (you may find the repository config is already in place if you’ve built Liberty projects with Maven before).

<profiles>
    <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <releases>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
          <id>ibm-maven-repo</id>
          <name>ibm-maven-repo</name>
          <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
          </snapshots>
          <id>ibm-maven-repo</id>
          <name>ibm-maven-repo</name>
          <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
        </pluginRepository>
      </pluginRepositories>
      <id>standard-extra-repos</id>
    </profile>
    <profile>
    	<id>cicsbt</id>
    	<activation>
    		<activeByDefault>true</activeByDefault>	
    	</activation>
    	<properties>
    		<cicsbt.dir>/usr/bin/cicsbt</cicsbt.dir>
    	</properties>
    </profile>
</profiles>
<activeProfiles>
    <activeProfile>standard-extra-repos</activeProfile>
</activeProfiles>

Setting up projects

Next, you need to set up projects in CICS Explorer. It’s simplest to create a new Web project using an appropriate Maven archetype, and then copy the source for the GENAPP web component into it. Then you can use Maven’s predefined project structure and minimise the configuration needed. So create a new Maven project (using File → New → Project → Maven project) with the following settings:

groupId = com.ibm.cics
artifactId = genapp.customer.search.web
version = 1.0.0

On the second page of the wizard, choose the archetype with group ID com.ibm.tools.archetype and artifact ID webapp-jee6-liberty . Next, use File → Import → Existing projects into workspace to import the web project for the GENAPP extension for Liberty, found in the zip file you downloaded. Copy over the source from the imported project’s src and WebContent folders into the main.java and main.webapp folders in the new Maven web project. You can then delete the imported web project.
Next, create a CICS bundle project and reference the web project. Use File → New → Project → CICS Resources → CICS Bundle project wizard. Then use the wizard found in File → New → Other → CICS Resources → Dynamic Web Project include to create the reference to web project. The resulting projects should look like this:
Screenshot of Eclipse project Explorer showing Maven web project

Adding CICS dependencies

You might have noticed that your web project doesn’t currently compile. This is because it’s missing the JCICS libraries from its classpath. To solve this, you need to add the JCICS jars to your project’s classpath. The Maven way to do is to add a dependency on JCICS in the project’s POM. As the JCICS JARs are not available in a public Maven respository, you’ll also need to add them to your local Maven repository. Alternatively, could add them to your organisation’s shared Maven repository. Once this has been done, in future you’ll just need to add the POM entry.
First, find the JCICS JAR file. It’s at the following location inside your Eclipse or CICS Explorer installation directory:
/plugins/com.ibm.cics.explorer.sdk.runtime_<version>/targets/cics/com.ibm.cics.server.jar
Then, add it to your local Maven repository by running the following at a command prompt (filling in the correct path):

 mvn install:install-file 
-Dfile=<path-to-com.ibm.cics.server.jar> 
-DgroupId=com.ibm.cics 
-DartifactId=server 
-Dversion=1.500 
-Dpackaging=jar 

Then, add the following dependency to the POM of your web project:

<dependency>
    <groupId>com.ibm.cics</groupId>
    <artifactId>server</artifactId>
    <version>1.500</version>
    <scope>provided</scope>   	
</dependency>

I’ve used scope provided here because the JCICS JARs will be available at runtime.

Your web project should now compile.

Creating a POM for a CICS bundle project

Now Maven knows how to build the web project, you need to tell it how to build the CICS bundle project. This is done by obtaining the built version of the web project and copying it into the bundle project, then invoking the CICS build toolkit.

To accomplish this, you’ll make your web project both a dependency and a module of the bundle project. Then, when you build the bundle project, the web project will automatically be built as a module. You can use the Maven dependencies plugin to copy the built WAR file into the bundle project’s output folder. Then in the package phase of the build, you can use the exec plugin to call the CICS build toolkit to finish the job. Here’s the complete POM, which you’ll need to create in the CICS bundle project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.ibm.cics</groupId>
	<artifactId>genapp.customer.search.bundle</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	
	<dependencies>
		<dependency>
			<groupId>com.ibm.cics</groupId>
			<artifactId>genapp.customer.search.web</artifactId>
			<version>1.0.0</version>
			<type>war</type>
		</dependency>
	</dependencies>
	
	<build>
		<plugins>
			<plugin>
			<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>2.10</version>
				<executions>
					<execution>
						<id>copy.built.bundleparts</id>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.basedir}</outputDirectory>
							<excludeTransitive>true</excludeTransitive>
							<stripVersion>true</stripVersion>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>exec-maven-plugin</artifactId>
				<version>1.4.0</version>
				<executions>
					<execution>
						<id>cicsbt</id>
						<goals>
							<goal>exec</goal>
						</goals>
						<phase>package</phase>
						<configuration>
							<executable>${cicsbt.dir}/cicsbt</executable>
							<arguments>
								<argument>-i</argument>
								<argument>${project.basedir}</argument>
								<argument>-o</argument>
								<argument>${project.build.outputDirectory}</argument>
								<argument>-b</argument>
								<argument>-v</argument>
							</arguments>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
	<modules>
            <module>../genapp.customer.search.web</module>
        </modules>
</project>

With the POM in place, you can now run a Maven build of the CICS bundle project from Eclipse. You can see the output from the CICS build toolkit in the Maven log, shown in the Eclipse console view. When the build completes, you’ll see the deployable form of the bundle project will be built into the target folder.

At this point, you’ve successfully defined a Maven build for a web project and the accompanying CICS bundle project. It’s now over to your build engineer to configure the project to build as part of your automated build system.

If you’d like to read more about how to reliably and repeatably build and deploy your CICS applications, have a look at this IBM Redbooks publication.

1 comment on"Using the CICS build toolkit with Apache Maven"

  1. this was also helpful, thanks

Join The Discussion

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