0

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.

userdr725
  • 25
  • 1
  • 6
  • maybe this answers your question? https://stackoverflow.com/questions/37052857/spring-overriding-one-application-property-from-command-line – Yonatan Karp-Rudin Nov 30 '22 at 16:29
  • no it doesn't, i tried it – userdr725 Nov 30 '22 at 16:30
  • Can you share a minimal project repository that can produce the issue, so I could have a look? – Yonatan Karp-Rudin Nov 30 '22 at 16:31
  • I'm surprised actually this was working fine minute ago and suddenly it stopped working . It's just not overwriting the properties in my application.properties. Am i using the correct syntax ?? for my command? – userdr725 Nov 30 '22 at 16:36
  • @YonatanKarp-Rudin 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. – userdr725 Nov 30 '22 at 17:21
  • I don't know if Spring works differently but that would normally be `-Dcom.records=10 -Dcom.count=10` etc. – g00se Nov 30 '22 at 17:25

2 Answers2

0

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"

userdr725
  • 25
  • 1
  • 6
0

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.