0

I have an application that has two profiles and it also takes a command line argument. I would like to run this application using java jar command but everytime I do that, only the default profile gets picked up.

application.properties (default profile)

endpoint=http://localhost:9999/success

application-prod.properties (prod profile)

endpoint=http://prod.server:5000/success

I tried executing following commands and both the time only the default profile got picked up.

java -jar target/app.jar hello 

java -jar target/app.jar hello -Pprod

Am I passing the spring boot profile name the correct way ?

Also please advise if this can be achieved using mvn spring-boot:run command?

Nital
  • 5,784
  • 26
  • 103
  • 195
  • 1
    java -jar -Dspring.profiles.active=prod application.jar https://stackoverflow.com/questions/31038250/setting-active-profile-and-config-location-from-command-line-in-spring-boot – Willem Sep 20 '19 at 20:09
  • Thanks Wilem, that worked. Any idea on how to do the same using `mvn spring-boot:run` command ? – Nital Sep 20 '19 at 20:12
  • Tried this `mvn spring-boot:run -Drun.jvmArguments="-Dspring.profiles.active=prod" hello` but got error. Looks like the `hello` added as command line argument is not the correct way to pass. – Nital Sep 20 '19 at 20:17
  • Did not work :( – Nital Sep 20 '19 at 20:23

1 Answers1

1

Oke so this should work:

mvn spring-boot:run -Dspring-boot.run.arguments="hello,--spring.profiles.active=prod"
Willem
  • 992
  • 6
  • 13