08-02-2023, 12:12 PM
We to faced similar issue while setting `spring.profiles.active` in java.
This is what we figured out in the end, after trying four different ways of providing `spring.profiles.active`.
In `java-8`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This works fine
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```
In `java-11`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This doesn't works
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```
**NOTE:** If you're specifying `spring.profiles.active` in your `application.properties` file then make sure you provide `spring.config.location` or `spring.config.additional-location` option to java accordingly as mentioned above.
This is what we figured out in the end, after trying four different ways of providing `spring.profiles.active`.
In `java-8`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This works fine
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```
In `java-11`
```
$ java --spring.profiles.active=dev -jar my-service.jar
Gives unrecognized --spring.profiles.active option.
```
```
$ java -jar my-service.jar --spring.profiles.active=dev
# This doesn't works
```
```
$ java -Dspring.profiles.active=dev -jar my-service.jar
# This works fine
```
```
$ java -jar my-service.jar -Dspring.profiles.active=dev
# This doesn't works
```
**NOTE:** If you're specifying `spring.profiles.active` in your `application.properties` file then make sure you provide `spring.config.location` or `spring.config.additional-location` option to java accordingly as mentioned above.