Showing posts from February, 2015

Scala : easily load an parse configuration files

There are a lot of ways to handle configuration files in a Scala program; my favorite one is to use TypeSafe's Config projectThis library scans the CLASSPATH for a predefined set of configuration files in different formatsUsing it it's pretty straightforward so let's get to it : 1.- Add your dependency to sbt libraryDependencies += "com.typesafe" % "config" % "1.2.1" 2.- Loading the configuration file //load the configuration file from the classpath val conf = ConfigFactory.load The convenience method ConfigFactory.load() loads the following (first-listed are higher priority):system propertiesapplication.conf (all resources on classpath with this name)application.json (all resources on classpath with this name) (all resources on classpath with this name)reference.conf (all resources on classpath with this name)The idea is that libraries and frameworks should ship with a reference.conf in their jar. Applications should p…