Reputation: 1089
I have a spring-boot application that is configured with a yml file. Is it possible to override these properties when executing the jar? For example let say I have the input variable in yml file set to user1 and I want to execute the jar with user2. Is it possible to do something like this?
java -jar --input=user2
Upvotes: 10
Views: 12698
Reputation: 21
this worked for me
java -Dspring.profiles.active=test-environment -jar config-server-0.0.1-SNAPSHOT.jar
If we see below syntax, it tells options should be included between java and -jar. Also, options are listed below as well.
Reason why this command works. Also, it takes the parameters instead of the application.yml configuration.
C:\Users\joy> java -?
Usage: java [-options] -jar jarfile [args...] (to execute a jar file) where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
**-D<name>=<value>
set a system property**
Note: Operating system is windows
Upvotes: 0
Reputation: 53462
To elaborate answer by cLyric, you can do this:
java -jar yourapp.jar --input=user2
Or if you want to provide using json, you can do
java -jar yourapp.jar --spring.application.json='{"input":"user2"}'
Or if you're in unix/linux,
SPRING_APPLICATION_JSON='{"input":"user2"}' java -jar yourapp.jar
Upvotes: 4