StraightforwardDev
StraightforwardDev

Reputation: 81

Run Spring batch with CommandLineJobRunner error impossible to find or load main class CommandLineJobRunner

I am new to Spring batch and want to run a batch with a command line using CommandLineJobRunner class, So I copied the generated jar file and CommandLineJobRunner to my Desktop and after I ran the following command:

Java -cp spring-batch-example.jar org.springframework.batch.core.launch. support. CommandLineJobRunner classpath: /jobs/file-import-job. xml simpleFileImportJob

which give this error (impossible to find or load main org. springframework. batch. core. launch. support. CommandLineJobRunner). I think that I should deal with the classpath, I don't know how doing it.

enter image description here enter image description here

Upvotes: 4

Views: 5996

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31590

You need to add Spring Batch jars to the classpath too, something like:

java -cp spring-batch-example.jar:lib/* org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/jobs/file-import-job.xml simpleFileImportJob

where lib contains Spring Batch jars and their dependencies. Note that if you are on windows, you need to use ';' instead of ':' to separate classpath entries.

I recommend to use maven shade plugin or a similar plugin to create an uber jar, or use Spring Boot and it will do it for you. In both cases, you would be able to run your job with:

java -jar spring-batch-example.jar

Upvotes: 4

Related Questions