Initial Setup of Nablarch batch Project for Container¶
The following is procedures of initial setup of the Nablarch batch project for container:
- Generating Nablarch batch project for container
- Confirm communications of Nablarch batch project
- Create a container image
- Run Container Image
Overview of the generated project¶
The overview of the project generated by this procedure is as follows.
Item | Description |
---|---|
Project type | Maven project |
Project composition | Single project composition |
DB used | H2 Database Engine (embedded in the application) |
What is included in the generated project? | The following is included in the generated project:
|
[1] | Email send batch functions as a resident batch and sends mail to the SMTP server.
Sample component configuration file is present in src/main/resources/mail-sender-boot.xml .
Email send batch is not necessary when building the initial environment, but when it becomes necessary, use after reading the description of send email. |
For relationship with other projects and directories, see Maven Archetype Configuration.
Create blank project¶
Generate a blank project using the archetypes provided by Nablarch.
Execute the mvn command¶
Use Maven Archetype Plugin(external site) to generate a blank project.
Change the current directory to the directory where the blank project (can be any directory) is to be created.
Execute the following command.
mvn archetype:generate -DarchetypeGroupId=com.nablarch.archetype -DarchetypeArtifactId=nablarch-container-batch-archetype -DarchetypeVersion=6u3
The version of Nablarch used in the above command is 6u3. If you want to change the version, change the following parameters.
Set value | Description |
---|---|
archetypeVersion | Specify the version of the archetype you wish to use. (Nablarch 6u2 or later must be specified) |
Enter project information¶
When the above command is executed, you will be asked to enter the following information about the blank project to be generated.
Input item | Description | Configuration example |
---|---|---|
groupId | Group ID (normally, enter the package name) | com.example |
artifactId | Artifact ID | myapp-container-batch |
version | Version number | 0.1.0 |
package | Package (normally the same as group ID) | com.example |
Important
Item groupId and package are mapped to the Java package name. Use lowercase letters, numbers, and dots for these input values, and do not use hyphens.
When you have finished entering project information, Y: : will appear.
- Enter 「Y」 if you want to generate a template based on the information you have entered.
- Enter 「N」 if you wish to redo the project information entry.
If the command ends normally, a blank project is created under the current directory.
Communication confirmation¶
The communication confirmation mechanism and procedures are the same as for a normal Nablarch batch project. Thus, see Initial Setup of the Nablarch Batch Project.
Note
The artifact ID should be replaced with myapp-container-batch
to specify the directory and command.
Create a container image¶
The blank project has a plugin named Jib (External sites) built in to create an image of a Docker container.
The jib: dockerBuild
goal of this plugin can be executed to create a container image.
cd myapp-container-batch
mvn compile jib:dockerBuild
If the execution is successful, the log given below will be output to the console.
(omission)
[INFO] Built image to Docker daemon as myapp-container-batch, myapp-container-batch, myapp-container-batch:0.1.0
[INFO] Executing tasks:
[INFO] [==============================] 100.0% complete
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
(Omitted)
Built Docker images are stored in a local repository. Can see the images stored in the local repository with the following command.
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
myapp-container-batch 0.1.0 1cafd4108237 51 years ago 253MB
myapp-container-batch latest 1cafd4108237 51 years ago 253MB
Can see that there are 2 images registered: myapp-container-batch:0.1.0
and myapp-container-batch:latest
.
As you can see, the blank project is configured to create the following two images by executing jib:dockerBuild
.
${project.artifactId}:latest
${project.artifactId}:${project.version}
OpenJDK image (External sites) is used as base image by default.
The base image can be changed with the jib.from.image
property.
For example, if you want to use eclipse-temurin:17.0.6_10-jre-jammy
for your base image, you would write it in pom.xml
.
<project>
<! -- Omitted ...-->
<properties>
<! -- Omitted ...-->
<jib.from.image>eclipse-temurin:17.0.6_10-jre-jammy</jib.from.image>
</properties>
<! -- Omitted ...-->
</project>
Tip
In the blank project, the base image is specified with a Docker image tag. In this case, the latest version of the specified image will be selected. If a different version is selected than at the time of verification, it may affect the operation of the application. Therefore, it is recommended to specify the base image as a digest in order to specify exactly which version, after the test is completed.
An example of setting by digest is shown below.
<jib.from.image>eclipse-temurin@sha256:7dacdab7c335d90cf4e110f5744ca27d5a3ed87901a7c08022c8c12055438bd2</jib.from.image>
Run a container image¶
Once you have created a container image, you can run it with the following command.
On-demand batch¶
cd myapp-container-batch
docker run --rm -v %CD%\\h2:/h2 -v %CD%\\src\\main\\format:/var/nablarch/format -v %CD%\\work\\output:/var/nablarch/output --name myapp-container-batch myapp-container-batch:latest -diConfig classpath:batch-boot.xml -requestPath SampleBatch -userId batch_user
It works the same as for Communication confirmation (on-demand batch)). If the startup is successful, a log similar to Launching the on-demand batch application will be output to the console.
Messaging Using Tables as Queues¶
cd myapp-container-batch
docker run -it --rm -v %CD%\\h2:/h2 --name myapp-container-batch --rm myapp-container-batch:latest -diConfig classpath:resident-batch-boot.xml -requestPath SampleResiBatch -userId batch_user
It works the same as for Communication confirmation (messaging using tables as queues) . If the startup is successful, a log similar to Launching the application will be output to the console. It will go into standby mode, so force quit it with ctrl+c after confirming.
Configure the database¶
The blank project is initially configured to use the H2 Database Engine. To change the RDBMS to be used, refer to Procedure for Changing the RDBMS used for the configuration.
In addition, to generate and execute DDL from ER diagrams and automatically generate entity classes, you need to initialize and run gsp-dba-maven-plugin. For details, see Initial Configuration Method of gsp-dba-maven-plugin (DBA Work Support Tool).
Supplementary notes¶
- About the commands to run the container image.
When the above command is executed, the container will be started, batch processing will be executed, and then the container will be terminated automatically. Also, -rm option is specified in order to make automatically container deleted when the container is ended.
The above command is an example of the case where SAMPLE.h2.db, which is included in the blank project beforehand, is used as the database. If you do not use SAMPLE.h2.db, you do not need to specify a volume (
-v
) for%CD%\\h2:/h2
.In addition to the above, in On-demand batch The blank project
./work/format
and./work/output
are mounted in a container.Even for Messaging Using Tables as Queues, the
-it option
of the docker command can be omitted, but the batch cannot be killed by ctrl+c from the docker host. In that case, exit the container with the following command.docker stop myapp-container-batch- About Docker
Running Docker assumes that you are using Docker Desktop (see Prerequisite). If you are using the Docker Toolbox, the volume specification in the above example will fail.
If you are using the Docker Toolbox, Docker is running in a VM on VirtualBox. Therefore, the path that can be specified on the host side of the volume is the path on the VM.
On Windows, by default
C:\Users
is mounted in/c/users
on the VM. Thus, if you are using the Docker Toolbox, you must specify the volume as-v/c/users/path/to/project/h2:/usr/local/tomcat/h2
.- About H2 and tools
- For information on the method of confirming the data of H2 and tools included in the blank project, see Initial Setup Procedure Supplementary Information.