Executing a job from the command line

A simple and robust way to execute a job is to use the command-line interface. This allows you to use a standard cron job (use the AT command on Windows) to schedule it, so that the job will be executed even if the web application is down. It's also convenient for testing and debugging a job.

Getting Ready

We'll use the job defined in the Creating a job recipe.

How to do it…

Follow these steps to execute the job from the command line:

  1. Declare the maven-assembly-plugin in pom.xml (under build/plugins):
     <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> org.springframework.batch.core.launch.support. CommandLineJobRunner </mainClass> </manifest> </archive> <descriptorRefs> ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.