Reputation: 392
I am having issues trying to use the variable substitution with the typesafehub ConfigFactory fileParser
my code is
Configuration(ConfigFactory.parseFile(new File("/Users/TDong/files/app.conf")).resolve())
and my app.conf file contains
path = ${java.home}
on every resolve I cannot resolve that variable with variable substitution to find the java system property home. Any ideas how to make this work
Upvotes: 1
Views: 3664
Reputation: 1120
To get advantage of the overriding features you need to stick with ConfigFactory.load()
or deal yourself with merging configuration through the Config#withFallback
method. In fact this is how
ConfigFactory#load()
works.
https://github.com/typesafehub/config#standard-behavior
The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):
- system properties application.conf (all resources on classpath with this name)
- application.json (all resources on classpath with this name)
- application.properties (all resources on classpath with this name)
- reference.conf (all resources on classpath with this name)
IMHO you should rely on the default behaviour and use -Dconfig.file=/path/to/your.conf
to pass files as arguments to your application.
I highly recommed to go through the documentation that is very well written.
Upvotes: 2
Reputation: 827
At path = ${java.home}
you are referring to other value under java.home
in the same configuration file. In order to override value you should run your application with
java -jar -Djava.home=VALUE your_jar.jar
or using some tool that allows you to pass arguments.
If you want to set this value by System.setProperty()
than you need to set it up before loading configuration file.
Upvotes: 1