Home > Back-end >  Application.properties values are not being overwritten by command line argument
Application.properties values are not being overwritten by command line argument

Time:12-01

I have two properties in my application properties and trying to overwrite them from command line arguments , but its not overwriting, I have checked the variable name/etc . all is fine but still isn't being overwritten. Please note: it was being overwritten earlier suddenly it stopped.

application.properties:
com.records=default
com.count=default

Command used to run from command line is: java -jar myJarname.jar "--com.records=10 --com.count=10"

Also, my program works perfectly fine when i try to overwrite just one command line argument and its able to do so. But when i try to over write application.properties with multiple command line arguments , it fails.

CodePudding user response:

Maybe the following format can helps you, i'm doing like this and i get the right values:

java -Dcom.records=10 -Dcom.count=10 -jar myJarname.jar

I just tried the next format and it works as well:

java -Dspring-boot.run.arguments="--com.records=10,--com.count=10" -jar myJarname.jar

I see that in both styles the parameters are before the -jar.

CodePudding user response:

I Was making a mistake with the syntax of commandline command , while passing command-line arguments, I was wrapping multiple arguments between " " and this was the issue. I simply ran the same command having multiple arguments separated by a space without wraaping them between "" and it worked just fine.

Correct Command: java -jar myJar.jar --com.arg1=10 --com.arg2=1

Incorrect Command: java -jar myJar.jar "--com.arg1=10 --com.arg2=1"

  • Related