Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run job parameters in spring batch with maven in CLI

I have seen several stackoverflow Q&As but none had a job parameter in CLI while using maven.

My parameter is setup like this:

@Value("#{jobParameters.getOrDefault('startTimestamp', null)}") Long startTimestamp
@Value("#{jobParameters.getOrDefault('endTimestamp', null)}") Long endTimestamp

My maven command is like this:

mvn clean spring-boot:run -Dspring.batch.job.names=myJob -Dspring.profiles.active=default,dev -f pom.xml

I am not sure what to add. the following is not working:

-Dspring.batch.job.startTimestamp=1667790578000
-Dspring.batch.job.parameters.startTimestamp=1667790578000
like image 768
Clark Ngo Avatar asked Oct 19 '25 12:10

Clark Ngo


1 Answers

From the command line, you can pass job parameters as key/value pairs:

java -jar myjob.jar name=foobar startTimestamp=1667790578000
like image 106
Mahmoud Ben Hassine Avatar answered Oct 21 '25 04:10

Mahmoud Ben Hassine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!