I want to add an object to the Global scope, and in order to construct it I need to pass it a path to a file. I don't want to hard code the file path in the source, and so I want to get that path from the application.conf.
The problem is that I don't know how to access these properties from the java class. I tried this:
Configuration.root().getString("file.path")
But it ends with a NullPointerException.
Am I wrong in assuming that there's a global Configuration instance that I can use? Thanks.
Try Play.application().configuration().getString("your.key")
As noted in the comment (nico_ekito), please use play.Play
and not play.api.Play
. play.api.Play
is for scala controllers (see comment by Marcus biesior Biesioroff)
Additionally, play uses https://github.com/typesafehub/config under the hood so it can also provide some insights.