Soumya Simanta Soumya Simanta - 1 year ago 147
Scala Question

Overriding multiple config values in Typesafe config when using an uberjar to deploy

I've an Akka application which uses multiple configuration values (IP address, port numbers) defined in

. I'm using the
plugin to create an uber jar and then deploying this jar.

Is there a way to override the whole
file by using another file that is outside the uber jar ? (i.e., values in the new conf file are used)

Answer Source

There are various ways to achieve that:

  1. You either set a classpath to include application.conf from external directory and appear on the classpath before other classpath entries like your jar. To do that you can use regular java -classpath myconfdir:theapp.jar and specify main class explicitly.

  2. You can alternatively include another conf file into your file with include "application" directive in your conf file.

  3. You can set environment variable in application.conf that will point to a file to include. You set env in shell afterwards.

  4. You can override values programmatically: config.withValue("hostname", ConfigValueFactory.fromAnyRef("localhost"). ActorSystem takes a Conf object or loads from default conf if not provided.

  5. The easiest by far is to just pick another file with -Dconfig.resource=/dev.conf java command line argument.

For more details refer to official docs here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download