Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

include configs from ${HOME}/.app/someconfig.conf

I need to include some properties file into my typesafe config, like

include ${user.HOME}"/.app/db-test.conf"

however parser complains:

com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}'
com.typesafe.config.ConfigException$Parse: dev/application.conf: 47: include keyword is not followed by a quoted string, but by: '${'user.HOME'}'
    at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:329)
    at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:325)
    at com.typesafe.config.impl.Parser$ParseContext.parseInclude(Parser.java:574)
    at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:624)
    at com.typesafe.config.impl.Parser$ParseContext.parseValue(Parser.java:408)
    at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:657)
    at com.typesafe.config.impl.Parser$ParseContext.parse(Parser.java:832)
    at com.typesafe.config.impl.Parser.parse(Parser.java:34)

How can I use system properties/environment variables in include statements?

like image 781
jdevelop Avatar asked Feb 15 '26 21:02

jdevelop


1 Answers

Can you do this manually in the code that loads your config?

Config baseConfig = ConfigFactory.load();
// Probably want error checking here.
Config testConfig = ConfigFactory.parseFile(
    new File(System.getenv("HOME") + "/.app/db-test.conf"));
// You may need to change your resolution order, depending on what you're doing in your 
// default config.
testConfig.resolve();
Config finalConfig = baseConfig.withFallback(testConfig);
like image 162
jkinkead Avatar answered Feb 19 '26 13:02

jkinkead