I don’t know how to call a task defined in Spring Batch using CommandLineJobRunner , the documentation is not enough for me.
I followed the Spring Batch official guide for writing jobs in a Spring Package using Java annotations, for example. @EnableBatchProcessing because I wanted to avoid the XML configuration files for job descriptions, steps, etc.
So far, I:
- configuration class (
com.package.bla.bla.ClassContainingTheBatchConfiguration see below), where I placed all the elements defining ItemReader , ItemProcessor , ItemWriter , Job and Step (with return jobs.get("nameOfTheJob") see below) using antagonism @Bean . - a class with the
main method with SpringApplication.run(...) and an annotation with @ImportResource("classpath:META-INF/spring/applicationContext.xml") to import some beans I need when processing data in Job.
On the Maven side, I now use some plugins:
maven-jar-plugin with <addClasspath>true</addClasspath> and a class containing the main method in the <mainClass>maven-assembly-plugin , because I need a unique jar executable containing all the materials in the dependencies, I use <phase>package</package> to be able to build a jar in the package phase, I also use <goal>single</goal> to be able to build the jar correctly using assemblymaven-compiler-plugin indicating that I am using Java 1.7
I think I configured everything that I need to configure, however after Maven BUILD SUCCESS I can not start the task from the command line:
java -cp ./target/JAR_FILE_NAME.jar org.springframework.batch.core.launch.support.CommandLineJobRunner com.package.bla.bla.ClassContainingTheBatchConfiguration nameOfTheJob
Throws an IOException due to java.io.FileNotFoundException regarding com.package.bla.bla.ClassContainingTheBatchConfiguration . How to specify options on the command line to complete the task?
source share