CICS-Run Java applications-(3) Build management with Gradle

Introduction

CICS TS V5.6 also supports Gradle as a build management tool for CICS-Java applications, along with Maven. Here, we will try build management of CICS-Java application using Gradle.

Related article

CICS-Run Java application-(1) Run simple sample application CICS-Run Java application-(2) Build management by Maven CICS-Run Java application-(3) Build management with Gradle CICS-Run Java application-(4) Spring Boot application

Advance preparation

This is similar to the Maven case. (Use Gradle instead of Maven)

Suitable Java EE development environment

Please use something that can develop Java EE applications such as Eclipse and VS Code as appropriate. Since we will use the sample as it is this time, we will not edit the source in particular, so we do not have to use it, but usually we will use some kind of development environment. It would be nice to be able to work with Gradle, git, etc. If you use CICS Explorer together, you can use Eclipse.

CICS Explorer

This is also not required, but it can be used to check the CICS resource definition. Download and set up an Eclipse-based tool called CICS Explorer, referring to the following areas. Reference: Downloading and starting CICS Explorer (https://www.ibm.com/support/knowledgecenter/SSSQ3W_5.5.0/com.ibm.cics.core.help/topics/concepts/install_planning_client.html)

Gradle Follow the steps below to install. Installing Gradle Basically, just unzip the downloaded one and pass it through the path.

As a prerequisite, Java 8 or later is required.

c:\>java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

Download the latest version of Gradle V6.5 at the moment from the following (gradle-6.5.zip). Releases

Extract it to a suitable directory. (Here (c: \ x \ Gradle \ gradle-6.5 ) Add the destination bin (C: \ x \ Gradle \ gradle-6.5 \ bin) to your PATH.

Verification

c:\>gradle -v

------------------------------------------------------------
Gradle 6.5
------------------------------------------------------------

Build time:   2020-06-02 20:46:21 UTC
Revision:     a27f41e4ae5e8a41ab9b19f8dd6d86d7b384dad4

Kotlin:       1.3.72
Groovy:       2.5.11
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          1.8.0_144 (Oracle Corporation 25.144-b01)
OS:           Windows 10 10.0 amd64

This is OK.

git

I will get and use the sample provided on gitHub, so I also have git installed. The setup method is omitted because it is lying around.

c:\>git --version
git version 2.21.0.windows.1

Execution environment (z / OS, CICS)

Prepare a CICS region to run the sample. For now, we'll use a region named ** CT56B4A1 ** under CICSplex control. Add a resource called JVMServer to run Java applications. This time, we will use the sample for CICS-Liberty (JavaEE application), so create a JVM Server for Liberty.

JVM profile

Prepare the JVM profile on USS. (Properties for the JVMServer are effectively specified in a file on this USS. The JVMSERVER resource definition points to the filename of this JVM profile.) A sample is provided, so copy it and use it.

Create a directory called /var/cicsts/cicsts56/CT56B4A1/JVMProfiles and copy /usr/lpp/cicsts/cicsts56/JVMProfiles/DFHOSGI.jvmprofile (sample definition for OSGi located under the CICS installation directory) to it. To do. Customize as appropriate for your environment.

DFHWLP.jvmprofile excerpt


JAVA_HOME=/usr/lpp/java/J8.0_64/
WORK_DIR=/var/cicsts/cicsts56/CT56B4A1/work
WLP_INSTALL_DIR=/usr/lpp/cicsts/cicsts56/wlp
-Dcom.ibm.cics.jvmserver.wlp.autoconfigure=true
-Dcom.ibm.cics.jvmserver.wlp.server.host=*
-Dcom.ibm.cics.jvmserver.wlp.server.http.port=56441
-Dcom.ibm.cics.jvmserver.wlp.server.https.port=56451
-Xms128M
-Xmx256M
-Xmso1M
-Xgcpolicy:gencon
-Xscmx256M
-Xshareclasses:name=cicsts%g,groupAccess,nonfatal
-Xtune:virtualized
-Dcom.ibm.tools.attach.enable=no
-Dfile.encoding=ISO-8859-1
_BPXK_DISABLE_SHLIB=YES

SIT

Specify the directory where the above properties file is located in the SIT parameter "JVMPROFILEDIR".

JVMPROFILEDIR=/var/cicsts/cicsts56/CT56B4A1/JVMProfiles 

Restart the region for the changes to take effect.

JVM Server definition

Prepare the JVMSERVER resource definition. Copy the JVMSERVER definition "DFHWLP" in the product-provided DFH $ WLP group to an appropriate group and install it.

OBJECT CHARACTERISTICS                                    CICS RELEASE = 0730
 CEDA  View JVmserver( DFHWLP   )                                            
  JVmserver      : DFHWLP                                                    
  Group          : TAGGRP                                                    
  DEScription    : CICS JVM server to run WLP samples                        
  Status         : Enabled            Enabled | Disabled                     
  Jvmprofile     : DFHWLP                                         (Mixed Case
  Lerunopts      : DFHAXRO                                                   
  Threadlimit    : 015                1-256                                  
 DEFINITION SIGNATURE                                                        
  DEFinetime     : 06/04/20 16:20:21                                         
  CHANGETime     : 06/04/20 16:20:21                                         
  CHANGEUsrid    : CICSUSER                                                  
  CHANGEAGEnt    : CSDApi             CSDApi | CSDBatch                      
  CHANGEAGRel    : 0730                                                                     

It is OK if it is enabled by looking at CEMT I JVMSERVER.

I JVMS                                             
STATUS:  RESULTS - OVERTYPE TO MODIFY              
 Jvm(DFHWLP  ) Ena     Prf(DFHWLP  ) Ler(DFHAXRO ) 
    Threadc(005) Threadl( 015 ) Cur(48314096)           

CICS Bundle Deployment API You must have set up the CICS Bundle Deployment API, which is available from CICS TS V5.6. This feature was added for application deployment as one of the REST-based management APIs called CMCI. Set up CMCI on the WUI server that manages the target CICS region, and specify the parameters for the CICS Bundle Deployment API in the CMCI JVM server properties. Reference: How it works: CICS bundle deployment API

The minimum required settings are as follows. Create a directory on USS for Bundle file placement. Here, it is / var / cicsts / cicsts56 / bundles. Set the following parameters in the JVM profile (EYUCMCIJ.jvmprofile) for WUI's CMCI JVM Server. -Dcom.ibm.cics.jvmserver.cmci.bundles.dir=/var/cicsts/cicsts56/bundles

Sample operation check

Local cloning

Clone https://github.com/IBM/cics-bundle-gradle.git to a directory on your local PC.

C:\y\workspace\cicsts56>git clone https://github.com/IBM/cics-bundle-gradle.git
Cloning into 'cics-bundle-gradle'...
remote: Enumerating objects: 125, done.
remote: Counting objects: 100% (125/125), done.
remote: Compressing objects: 100% (87/87), done.
remote: Total 1855 (delta 43), reused 86 (delta 13), pack-reused 1730Receiving objects:  99% (1837/1855), 2.08 MiB | 2.01 MiB/s
Receiving objects: 100% (1855/1855), 4.19 MiB | 2.83 MiB/s, done.
Resolving deltas: 100% (610/610), done.

Understanding file structure

I will use a sample called gradle-multipart-sample under samples, so move the directory and see the structure of the file.

C:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample>tree /f /a
List of folder paths:Volume Windows
Volume serial number is 1866-E2FC
C:.
|   build.gradle
|   gradlew
|   gradlew.bat
|   README.md
|   settings.gradle
|
+---gradle
|   \---wrapper
|           gradle-wrapper.jar
|           gradle-wrapper.properties
|
+---gradle-bundle-demo
|       build.gradle
|
\---gradle-war-demo
    |   build.gradle
    |
    \---src
        \---main
            +---java
            |   \---demo
            |           SimpleServlet.java
            |
            \---web-app
                |   index.html
                |   index.js
                |   style.css
                |
                +---images
                |       cics.png
                |
                \---WEB-INF
                        web.xml


There are multiple build.gradle and it has a hierarchical structure, which is a structure called "multi-project" of Gradle. Reference: Basics of multi-project with Gradle

Normally, when creating a CICS-Java application, create an OSGi project (jar) or Web project (WAR) that is the main body of the application, create a CICS bundle project to organize the application, and deploy these as a group package. Do that. In this sample, the gradle-war-demo part corresponds to the project of the application body (WAR), the gradle-bundle-demo part corresponds to the CICS bundle project, and in order to package them together, the parent's as a multi-project It is summarized in the gradle-multipart-sample project. The relationship of build.gradle is as follows. image.png

It seems that you can also display the relationship of the project with the following command.

c:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample>gradle -q projects

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'gradle-multipart-sample'
+--- Project ':gradle-bundle-demo'
\--- Project ':gradle-war-demo'

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :gradle-bundle-demo-test04:tasks

Check / edit contents

gradle-war-demo (javaEE app)

This is a web application that is supposed to run on CICS-Liberty. It is implemented with simple html and Servlet. (It looks like the Maven sample)

SimpleServlet.java


package demo;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.cics.server.InvalidRequestException;
import com.ibm.cics.server.Task;

/**
 * Servlet implementation class SimpleServlet
 */
@WebServlet("/SimpleServlet")
public class SimpleServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");

        response.getWriter().print("Hello world!");
        Task task = Task.getTask();

        try {
            String userid = task.getUSERID();
            response.setContentType("text/html");
            response.getWriter().print("\nI am " + userid);
        } catch (InvalidRequestException e) {
            throw new RuntimeException(e);
        }
    }

}

The process is to acquire the object of the own task running in the Task Class of JCICS, acquire the user information that is executing itself from it, and display it.

There is no need to change the app itself, so just check the contents.

gradle-bundle-demo (CICS bundle)

Normally, when creating a CICS-Java application with CICS Explorer (when not using Gradle), you will create a CICS bundle project and set the application (WAR, OSGi, etc.) to be incorporated in it. As a result, files such as cics.xml and xxx.warbundle will be created.

This is the equivalent of the CICS bundle project, but only build.gradle exists. By specifying the dependency using the Gradle mechanism, it seems that the Gradle plug-in (cics-bundle-gradle) provided by CICS automatically creates the files required for the CICS bundle project. Therefore, as a user, you only need to make the necessary settings in build.gradle, and you do not have to be directly aware of the CICS bundle project.

Edit build.gradle for your environment. Changes are described in comments (1)-(7)

gradle-bundle-demo-test04\build.gradle


plugins {
    id 'com.ibm.cics.bundle' version '1.0.0'
}

group 'com.ibm.cics'
version '1.0.0'

repositories {
    mavenCentral()
}

cicsBundle {
    build {
        defaultJVMServer = 'DFHWLP' // (1)JVMSERVER name
    }
    deploy {
        cicsplex = 'C73PLX'         // (2)The CICSplex name to which the target CICS region belongs
        region   = 'CT56B4A1'       // (3)Target CICS region name
        bunddef  = 'GRDBUNDL'       // (4)Bundle-defined resource name defined on the target CICS region
        csdgroup = 'TAGGRP'         // (5) (4)CSD group name to which the bundle definition of
        url = 'http://etp1:56002'   // (6)WUI CMCI URL
        username = 'TAG'            // (7)With the user used when issuing the Deployment API by CMCI
        password = '********'       //password
        //caution: uncomment the line below to disable TLS/SSL checking for certificates
        //insecure = true
    }
}

dependencies {
    cicsBundlePart group: 'org.codehaus.cargo', name: 'simple-war', version: '1.7.7', ext: 'war'
    cicsBundlePart project(path:':gradle-war-demo', configuration: 'archives')
}

Now, I changed the directory name of the CICS bundle project from gradle-bundle-demo to gradle-bundle-demo-test04. This directory name will be used as the directory name when transferring products over USS. A directory called <CICS bundle project name> _ <version> is created in the directory for bundling directory placement specified by the JVM Server of WUI (here / var / cicsts / cicsts56 / bundles), and various files are created. Is expanded. Example: /var/cicsts/cicsts56/gradle-bundle-demo-test04_1.0.0/

Other change parameters are as follows.

** (1) defaultjvmserver **: Specify the name of the JVMSERVER to run the app. It must be installed in the target CICS region in advance. ** (2) CICSplex **: CICSplex name to which the target CICS region belongs ** (3) region **: Target CICS region name ** (4) bundledef **: Bundle definition resource name defined on the target CICS region ** (5) csdgroup **: CSD group name to which the bundle definition in (5) belongs ** (6) url **: Specify the URL of CMCI of WUI. The CICS Bundle Deployment API must be enabled for this WUI. (If it is a template, there is no description of http: //, but if you do not specify this, an error will occur, so be careful!) ** (7) username / password **: User and password used when issuing Deployment API by CMCI

Since we've renamed the project directory, we'll modify the parent setting.gradle accordingly.

setting.gradle


rootProject.name = 'gradle-multipart-sample'
include 'gradle-war-demo'
include 'gradle-bundle-demo-test04'

BUNDLE definition creation

Create a bundle definition according to the contents specified in build.gradle above.

OBJECT CHARACTERISTICS                                    CICS RELEASE = 0730
 CEDA  View Bundle( GRDBUNDL )                                               
  Bundle         : GRDBUNDL                                                  
  Group          : TAGGRP                                                    
  DEScription    : CICS-BUNDLE-DEMO                                          
  Status         : Enabled            Enabled | Disabled                     
  BUndledir      : /var/cicsts/cicsts56/bundles/gradle-bundle-demo-test04_1.0
  (Mixed Case)   : .0                                                        
                 :                                                           
                 :                                                           
                 :                                                           
  BAsescope      :                                                           
  (Mixed Case)   :                                                           
                 :                                                           
                 :                                                           
                 :                                                           
 DEFINITION SIGNATURE                                                        
  DEFinetime     : 06/17/20 14:19:33                                         

The CSD group is specified (5), the BUNDLE definition name is (4), and BUNDLEDIR is specified based on the directory name and version information value of the project.

Sample modification

I feel that it will be fixed soon, but there is a defect in the directory structure of the provided sample, and if the subsequent processing is executed as it is, the sample operation will not work well. There is a directory called ... \ gradle-multipart-sample \ gradle-war-demo \ src \ main \ web-app \, but change this web-app to webapp. Let's remove the hyphen). As for the operation of Gradle's War plugin, the files under webapp are copied when creating WAR by default, but since it is web-app in the sample, web.xml and index.html under this directory Etc. will not be copied and the sample application will not be able to be called.

Reference: Gradle --The War Plugin

The default behavior of the War task is to copy the content of src/main/webapp to the root of the archive. Your webapp directory may of course contain a WEB-INF sub-directory, which may contain a web.xml file. Your compiled classes are compiled to WEB-INF/classes. All the dependencies of the runtime [1] configuration are copied to WEB-INF/lib.

Build / deploy execution

To build, run the following command under the gradle-multipart-sample directory. At first, it takes time because the necessary packages are downloaded.

c:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample>gradlew build
Downloading https://services.gradle.org/distributions/gradle-5.0-all.zip
...........................................................................................................................

Welcome to Gradle 5.0!

Here are the highlights of this release:
 - Kotlin DSL 1.0
 - Task timeouts
 - Dependency alignment aka BOM support
 - Interactive `gradle init`

For more details see https://docs.gradle.org/5.0/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> Task :gradle-bundle-demo-test04:buildCICSBundle
Adding Java-based bundle parts from 'cicsBundlePart' dependency configuration
Adding Java-based bundle part: 'C:\Users\TomohiroTaguchi\.gradle\caches\modules-2\files-2.1\org.codehaus.cargo\simple-war\1.7.7\5f462015066db63c2e240b4fc3674c6f4910bb73\simple-war-1.7.7.war'
Adding Java-based bundle part: 'C:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample\gradle-war-demo\build\libs\gradle-war-demo-1.0.0.war'
Adding non-Java-based bundle parts from 'src/main/resources'

BUILD SUCCESSFUL in 1m 12s
4 actionable tasks: 4 executed

The project is now built. Under the gradle-bundle-demo directory, each file of the CICS bundle project and a zip file (used at the time of deployment) that summarizes them are generated.

c:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample>tree gradle-bundle-demo-test04 /f /a
List of folder paths:Volume Windows
Volume serial number is 1866-E2FC
C:\Y\WORKSPACE\CICSTS56\CICS-BUNDLE-GRADLE\SAMPLES\GRADLE-MULTIPART-SAMPLE\GRADLE-BUNDLE-DEMO-TEST04
|   build.gradle
|
\---build
    +---distributions
    |       gradle-bundle-demo-test04-1.0.0.zip
    |
    \---gradle-bundle-demo-test04-1.0.0
        |   gradle-war-demo-1.0.0.war
        |   gradle-war-demo-1.0.0.warbundle
        |   simple-war-1.7.7.war
        |   simple-war-1.7.7.warbundle
        |
        \---META-INF
                cics.xml

Next, perform the deployment work. Execute the following command under the gradle-multipart-sample directory.

c:\y\workspace\cicsts56\cics-bundle-gradle\samples\gradle-multipart-sample>gradlew deployCICSBundle

> Task :gradle-bundle-demo-test04:deployCICSBundle
Task deployCICSBundle

BUILD SUCCESSFUL in 12s
5 actionable tasks: 1 executed, 4 up-to-date

If you look at the status of the bundle and bundle parts in CICS Explorer, you can see that they have been successfully installed and enabled. image.png

In other words, the above Gradle command has performed the following processing.

Build: Compile Java EE application (gradle-war-demo) / Create WAR, Generate CICS bundle (gradle-bundle-demo) Package: Packaging of related modules Deploy: Transfer / deploy CICS bundle files to USS, install BUNDLE definition

App operation check

Try accessing the Liberty-deployed app running on the target CICS from your browser. image.png

Since it is running as the default user "CICSUSER", that user name is displayed.

With this, I was able to confirm that the application works properly!

Recommended Posts

CICS-Run Java applications-(3) Build management with Gradle
CICS-Run Java applications-(2) Build management with Maven
Build and test Java + Gradle applications with Wercker
Build a Java project with Gradle
First gradle build (Java)
Build Java with Wercker
Using Gradle with VS Code, build Java → run
Java multi-project creation with Gradle
CICS-Run Java applications-(5) Use JCICSX
Easily Docker Java applications with Jib
Java build with mac vs code
[Gradle] Build a Java project with a configuration different from the convention
[Java] Create an executable module with Gradle
Monitor Java applications with jolokia and hawtio
Build OpenCV with Java Wrapper on Ubuntu 18.04
Java automated test implementation with JUnit 5 + Gradle
Create Java applications with IBM Cloud Functions
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Java management and STS (Eclipse) build path settings
vagrant java build
Static code analysis with Checkstyle in Java + Gradle
Run Scala applications with Spring Boot through Gradle
Build Java x Spring x VSCode x Gradle on Docker (1)
Build an E2E test environment with Selenium (Java)
Build Spring Boot project by environment with Gradle
Build a Java development environment with VS Code
Build Java development environment with VS Code on Mac
Build VS Code + WSL + Java + Gradle environment from scratch
CI the architecture of Java / Kotlin applications with ArchUnit
How to build docker environment with Gradle for intelliJ
How to build Java development environment with VS Code
Check coverage with Codecov in Java + Gradle + Wercker configuration
Build Java program development environment with Visual Studio Code
Install java with Homebrew
Use ProGuard with Gradle
Change seats with java
Install Java with Ansible
[Java] Package for management
Build Doma1 with Ant
Comfortable download with JAVA
java build a triangle
Install Gradle with ubuntu16.04
Switch java with direnv
DataNucleus starting with Gradle
Build Growai with Centos7
Download Java with Ansible
Let's scrape with Java! !!
Use WebJars with Gradle
Get started with Gradle
Use jlink with gradle
Build bazel with alpine
Endian conversion with JAVA
Use Java included with Android Studio to build React Native
[Java] Simplify the implementation of data history management with Reladomo
[Java] [Play Framework] Until the project is started with Gradle
Build WebAPP development environment with Java + Spring with Visual Studio Code
[Java] Sample project for developing web applications with Spring Boot
Easily convert Java application to Docker container with Jib ~ Build with gradle and register in local repository