Issue
I have a config file in the below folder subtract
main
scala
resources
application.conf
and that contains
path{
http{
url = "http://testingurl"
}
}
import com.typesafe.config.Config;
val url = conf.getString("path.http.url")
I am reading this static information which is provided durng build time.
Now I want to read these in runtime, user should be able to modify configs even after jar is built.
my requirement is to modify url event after jar is build, I dont want to pass as a arguments to the main function because I have so many such values which needs to modified after jar built
Solution
Use at runtime:
-Dconfig.file=<relative or absolute path>
See:
For applications using application.{conf,json,properties},
system properties can be used to force a different config source
(e.g. from command line -Dconfig.file=path/to/config-file):
config.resource specifies a resource name - not a basename, i.e. application.conf not application
config.file specifies a filesystem path, again it should include the extension, not be a basename
config.url specifies a URL
These system properties specify a replacement for application.{conf,json,properties}, not an addition.
They only affect apps using the default ConfigFactory.load() configuration.
In the replacement config file, you can use include "application" to include the original default config file;
after the include statement you could go on to override certain settings.
Answered By - Andrzej Jozwik
Answer Checked By - Marilyn (JavaFixing Volunteer)