2

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
Clark Ngo
  • 343
  • 4
  • 14

4 Answers4

2

if you want to pass job parameters with maven, you can use:

mvn spring-boot:run -Dspring-boot.run.arguments="param1=value1 param2=value2"

You can find here the documentation.

1

Job parameters are set through the jobLauncher. For example:

JobParameters jobParameters = new JobParametersBuilder()
    .addLong("startTimestamp", 1667790578000L).toJobParameters();

JobExecution execution = jobLauncher.run(job, jobParameters);

If you want to send the parameter as a property, you need to use the @Value annotation to inject your custom property into the bean that launches the job.

html_programmer
  • 18,126
  • 18
  • 85
  • 158
1

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

java -jar myjob.jar name=foobar startTimestamp=1667790578000
Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
1

I found this to be working.

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

found the stackoverflow: Get command-line arguments from spring-boot:run

Clark Ngo
  • 343
  • 4
  • 14