How to use play framework config library command line parameters in non play application

910 Views Asked by At

In play application I can add command line parameters to override default config in resourses:

... -Dconfig.file=/opt/conf/prod.conf

I develop non-play application with play config library and generate jar with sbt-assembly.

Upd
I want use command line params:

java -jar my-app.jar -Dconfig.file=/opt/conf/prod.conf

but there is no effect. I load config with:

ConfigFactory.load()

Should I manually resolve cmd params and load file into config?

2

There are 2 best solutions below

0
zella On BEST ANSWER

I found mistake:

-Dconfig.file is a system parameter. System parameters should be written before -jar. Other way they are interpreted as command line parameters. So correct solution:

java -Dconfig.file=/opt/conf/prod.conf -jar my-app.jar
1
tsuyoshi On

Play just use typesafe-config. https://github.com/typesafehub/config

You can use same feature by adding the dependency into your build.sbt, and use Config class.