I need to expand environment variables in a string. For example, when parsing a config file, I want to be able to read this...
statsFile=${APP_LOG_DIR}/app.stats
And get a value of "/logs/myapp/app.stats", where the environment variable APP_LOG_DIR = "/logs/myapp".
This seems like a very common need, and things like the Logback framework do this for their own config files, but I have not found a canonical way of doing this for my own config files.
Notes:
This is not a duplicate of the many "variable interpolation in java strings" questions. I need to interpolate environment variables in the specific format ${ENV_VAR}.
The same question was asked here, Expand env variables in String, but the answer requires the Spring framework, and I don't want to pull in this huge dependency just to do this one simple task.
Other languages, like go, have a simple built-in function for this: Interpolate a string with bash-like environment variables references. I am looking for something similar in java.