Initial Setup of the Nablarch Batch Project

The following is procedures of initial setup of the Nablarch batch project:

  • Generate the Nablarch batch project
  • Confirm communications of the Nablarch batch project

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:

  • Basic configuration for the Nablarch batch application
  • On-demand batch application for communication confirmation
  • Messaging using tables as queues for communication confirmation
  • Email send batch configuration [1]
  • Initial configuration of the tool that operates in conjunction with Maven (is imported by referring to nablarch-archetype-parent (parent 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-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-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 (on-demand batch)

Automated test (on-demand batch)

The following unit tests are included in the project generated from the archetype.

Unit test classes Test content
SampleBatchActionRequestTest Use the Nablarch testing framework to check if the batch can be launched.

Execute the unit test and confirm that the blank project was successfully generated.

Execute the following command.

cd myapp-batch
mvn test

If the execution is successful, the log given below will be output to the console.

(omitted)
[INFO] ----------------------< com.example:myapp-batch >-----------------------
[INFO] Building myapp-batch 0.1.0
[INFO] --------------------------------[ jar ]---------------------------------
(omitted)
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
(rest is omitted)

Launch test (on-demand batch)

The on-demand batch is included in the generated project.

Batch class Details
SampleAction Confirm communications of the Nablarch functions commonly used when implementing batch applications.

Confirm that the blank project has been successfully generated by launching on-demand batch.

Build a batch application

If the current directory is not yet moved to the generated project, move the directory.

cd myapp-batch

Execute the following command to build the batch application.

mvn package

Launching the on-demand batch application

Execute the following command.

mvn exec:java -Dexec.mainClass=nablarch.fw.launcher.Main ^
    -Dexec.args="'-diConfig' 'classpath:batch-boot.xml' '-requestPath' 'SampleBatch' '-userId' 'batch_user'"

If the launch is successful, the log given below will be output to the console.

2020-04-28 08:56:23.353 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 疎通確認を開始します。
2020-04-28 08:56:23.379 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 取得したコード名称:ロック
2020-04-28 08:56:23.383 -INFO- com.example.SampleBatch [202004280856233530002] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] 疎通確認が完了しました。
2020-04-28 08:56:23.396 -INFO- nablarch.fw.handler.MultiThreadExecutionHandler [202004280856233470001] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user]
Thread Status: normal end.
Thread Result:[200 Success] The request has succeeded.
2020-04-28 08:56:23.407 -INFO- nablarch.core.log.app.BasicCommitLogger [202004280856233470001] boot_proc = [] proc_sys = [batch] req_id = [SampleBatch] usr_id = [batch_user] TOTAL COMMIT COUNT = [1]
2020-04-28 08:56:23.413 -INFO- nablarch.fw.launcher.Main [null] boot_proc = [] proc_sys = [batch] req_id = [null] usr_id = [null] @@@@ END @@@@ exit code = [0] execute time(ms) = [559]

Communication confirmation (messaging using tables as queues)

The following application is included in the generated project.

Batch class Details
SampleResiAction An application that implements the basic process “fetch values from the table to be processed and set a processed flag” of messaging using a table as a queue

Confirm that the blank project has been successfully generated by launching the above application.

Launch test (messaging using tables as queues)

Build an application

If it has not yet been built, see Build a batch application and build.

Launch the application

Execute the following command.

mvn exec:java -Dexec.mainClass=nablarch.fw.launcher.Main ^
    -Dexec.args="'-diConfig' 'classpath:resident-batch-boot.xml' '-requestPath' 'SampleResiBatch' '-userId' 'batch_user'"

Tip

The differences between the above arguments and the on-demand batch application are as follows.

  • xml file specified by -diConfig
  • Request path specified by -requestPath

If the launch is successful, the log given below will be output to the console.

2020-04-28 08:58:15.350 -INFO- nablarch.fw.reader.DatabaseTableQueueReader [202004280858153390001] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] read database record. key info: {USER_INFO_ID=00000000000000000001}
2020-04-28 08:58:15.356 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] handleが呼ばれました。
2020-04-28 08:58:15.363 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] USER_INFO_ID:00000000000000000001
2020-04-28 08:58:15.367 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] LOGIN_ID:TAROU
2020-04-28 08:58:15.371 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] KANA_NAME:たろう
2020-04-28 08:58:15.379 -INFO- com.example.SampleResiBatch [202004280858153560002] boot_proc = [] proc_sys = [batch] req_id = [SampleResiBatch] usr_id = [batch_user] KANJI_NAME:太郎

Forcibly terminate with ctrl + c.

Important

Nablarch assumes that the correct way to exit is to use the BATCH_REQUEST table The method is to set the flag of PROCESS_HALT_FLG to 1. In this procedure, we use ctrl + c to stop it for simplicity.

If you want to restart the messaging with the table as a queue after the termination, see To Restart Messaging Using Tables as Queues.

If the communication confirmation fails for some reason

If the communication confirmation fails for some unknown reason, the correct procedure may not have been followed in some part.

If the reason is not known, try again from Create blank project.

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

For information on the method of confirming the data of H2 and tools included in the blank project, see Initial Setup Procedure Supplementary Information.