Book Image

Spring Cookbook

Book Image

Spring Cookbook

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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>
                    &lt...