This page describes how to create a self contained Spring Batch Application using Maven 2.
Background
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.
Requirements
- 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.
hi,
I am a newbie in spring ,I tried to package and run the hello world job example ,but facing the following error
SEVERE: Job Terminated in error: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [simpleJob.xml]
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: class path resource [simpleJob.xml]
I am also getting the same above error ? Any idea Y this is happening . Please guide me
Just tried it the second time and everything works fine for me. Please ensure that you have the right version of spring in the classpath by verifying the dependencies in the pom.xml file. Also verify that you don’t have another version of spring in the classpath. The error you are getting sometimes happens when you have spring 1.x.x in your classpath. The xml namespace only appeared after spring batch 2.x.
I am getting the error while running the application:
nested exception is java.io.FileNotFoundException: class path resource [simpleJob.xml] canno
t be opened because it does not exist
is the simpleJob.xml located in src/main/resources/ folder?
Yes. It is located under src/main/resources folder. But in target folder it is under target/classes folder. Jar is under target folder.
If you are getting the above error regarding the Spring XML namespace, you will probably have to use the maven shade plugin. I added the approved answer to my pom, and ran mvn:shade:shade and it worked like a champ. See the following link: http://stackoverflow.com/questions/8523997/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace-http-www-sp