A step can consist of just an execution of a system command. Spring Batch provides a convenient class for this, SystemCommandTasklet
.
In Spring Batch's configuration file, add a SystemCommandTasklet
bean. Declare the system command to be executed (here, we used the touch Unix command to create an empty file), the directory to execute it from, and the maximum time allowed for its execution:
@Bean public SystemCommandTasklet task1() { SystemCommandTasklet tasklet = new SystemCommandTasklet(); tasklet.setCommand("touch test.txt"); tasklet.setWorkingDirectory("/home/merlin"); tasklet.setTimeout(5000); return tasklet; }