This page describes how to create a self contained Spring Batch Application using Maven 2.
Self contained jars are executable and can run independently. Maven includes all the runtime dependencies into these jars so that the jar’s can be run by executing the the “java -jar” command.
- Maven 2
- Successful completion of Hello World with spring Batch tutorial.
We will continue where we left off in my last tutorial.
Add the following plugin to the pom.xml file
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> org.springframework.batch.core.launch.support.CommandLineJobRunner </mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin>
Package the application
The following command packages the JAR file and includes all the runtime dependencies.
mvn clean compile assembly:single
Run the application
Open up a command line window and navigate to the project base folder. The self contained jar is located in the target folder. CD to the folder and execute the following.
java -jar springBatchHelloWorld-1.0-SNAPSHOT-jar-with-dependencies.jar simpleJob.xml helloWorldJob
You should notice a bunch of output including the “Hello World” message.