Search code examples
scalaplayframeworkconfiguration-files

How to read system variable into a conf file in Play framework


I would read an environment variable like this below

my.key = ${?MY_KEY_ENV}

But how to read a system variable that's passed in via

-Dmysystem.var=XXX

It is not being resolved in my conf file


Solution

  • assuming your project is managed via SBT. make sure you have the following set in the build file

    javaOptions in Global += "-Dmysystem.var=XXX"
    

    and your application.conf file has the following

    my_key=${mysystem.var}
    

    and now you should be able to be refer the my_key using the below code

    configuration.getString("my_key")
    

    tested this in my play app and it is working as expected.