Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

scala - 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 resource/application.conf. I'm using the sbt-assembly plugin to create an uber jar and then deploying this jar.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...