How to run a specific job using Maven command in Spring Batch?

Viewed 42

Given you have this job configuration below, how can you execute the job scrubWord in command line in a Spring Boot - Spring Batch application using Maven command?

@Configuration
public class WordConfiguration {

    @Autowired
    WordReader wordReader;

    @Autowired
    WordProcessor wordProcessor;

    @Autowired
    WordWriter wordWriter;

    @Bean
    public Job scrubWords() {
        Step scrubWords = stepBuilders
                .get("scrubWord")
                .<Set<String>, Set<String>>chunk(1)
                .reader(wordReader)
                .processor(wordProcessor)
                .writer(wordWriter)
                .build();
        return jobBuilders.get("wordScrubber")
                .start(scrubWords)
                .build();
    }
}
3 Answers

You can also run the executable jar as follows

java -Dspring.batch.job.names=myJob -jar myjar.jar [job parameters]
mvn clean spring-boot:run -Dspring.batch.job.names=wordScrubber 
  • clean to overwrite previously compiled files in target/classes.
  • spring-boot:run start ups spring boot.
  • -Dspring.batch.job.names=<jobName> run a specific batch job.
Related