Alihan Şimşek
Alihan Şimşek

Reputation: 3

How to pass command line arguments to Spring Batch

This is my first time working on a spring batch project. So I need to know how to pass arguments to the main class in a .sh file. The project is currently working and .sh file has a command line like this:

java -Xmx2048M -jar somebatch-SNAPSHOT.jar applicationContext.xml

And I want to pass arguments by changing this command. the project runs all jobs at the main class so job names are not specified in the command. What I want to do is pass arguments so I can select which jobs will run. Something like this:

java -Xmx2048M -jar somebatch-SNAPSHOT.jar --argument 1 applicationContext.xml

I don't need to pass the arguments to the jobParameters like java -jar somejar.jar somejob value=1 as shown in some examples. I only need a value in the main class.

Any help is appreciated.

Upvotes: 0

Views: 7111

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31600

I don't need to pass the arguments to the jobParameters like java -jar somejar.jar somejob value=1 as shown in some examples. I only need a value in the main class.

In this case, you can pass parameters on the command line with -Dparam=value and then get them in your main class using System.getProperty("param").

Upvotes: 3

Related Questions