Play 2.4.3 : Reading content from config file

108 views
Skip to first unread message

Bond

unread,
Oct 16, 2015, 12:41:09 AM10/16/15
to play-framework
I'm able to read the contents that are stored in the conf/application.conf using the command
 
val port= Play.application().configuration().getInt("port")
 
But I have created one more file in conf directory.    conf/properties.conf and stored the values there.
 
But i'm not able to find how to read from a custom property file.
 
 
 
Please any one help me

Erol Merdanović

unread,
Oct 16, 2015, 12:17:45 PM10/16/15
to play-framework
Hello

Have you tried with https://github.com/typesafehub/config ? With it you can read from custom properties file.

Daniel Manchester

unread,
Oct 16, 2015, 1:43:41 PM10/16/15
to play-framework
Hi,

If you aren't able to read the custom property file with a configuration API (like the one Erol mentioned), you could also rely on Play's placement of the "conf" directory's contents on the classpath. You'd get an InputStream to the file and work from there:

val file = "properties.conf"

val inputStream = play.api.Play.resourceAsStream(file).getOrElse {
  throw new NullPointerException(s"Could not find resource '$file'!")
}

...

Dan
Reply all
Reply to author
Forward
0 new messages