1

I am using JCommander API for a Spring Boot - Spring Batch project.

Project has multiple jobs and I need to pass job name as parameter so I can launch specific jobs .

java -jar myJar.jar -jobName job1

Now, if my job1 is running and I wish to launch job2 at that time, I couldn't do that since port is already is in use. So I would be able to launch job2 only when job1 is finished.

If I try to launch job2 at different port ,

java -jar myJar.jar -jobName job2 --server.port=8090

then jCommander is not letting it through since I have not defined server.port in JCommander configuration and even if I do that , Spring Boot picks property from property file only and tries to run at same port - 8080.

How to handle this scenario?

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98

1 Answers1

0

documentation for Spring Boot says:

You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration.

you should be able to configure server.port like this:

java -jar myJar.jar -Dserver.port=8090 -jobName job2

afaik you could set SERVER_PORT environment variable too:

SERVER_PORT=8090 java -jar myJar.jar -jobName job2
Yevgeniy
  • 2,614
  • 1
  • 19
  • 26
  • Got this - `Caused by: com.beust.jcommander.ParameterException: Was passed main parameter '-Dserver.port=8090' but no main parameter was defined in your arg class` ...which basically means that jcommander stopped it. Setting an environment variable is not an option for me. – Sabir Khan Jul 13 '17 at 09:30