keyboardsamurai
keyboardsamurai

Reputation: 701

Akka won't override application.conf with command line parameters

I thought since akka 2.1.4 uses typesafe config, it would just override whatever -D parameter I throw at it via command line, like play framework does. Turns out it doesn't seem to work that way. Just adding a -Dakka.remote.netty.port=2552 doesn't really change anything when added in to the commandline. Do I have to enable anything to make overrides work?

Additional info: I tried using the -D parameters in the Intellij launcher and with java -cp app.jar -Dakka.remote.netty.port=2552 after doing an sbt assembly

Upvotes: 3

Views: 5178

Answers (2)

An Illusion
An Illusion

Reputation: 777

I ran into this same issue. I was using 'java -jar project.jar -Dblah=whatever' to run the project which was not overriding the conf file. But, 'java -jar -Dblah=whatever project.jar' did override the conf file.

Upvotes: 4

keyboardsamurai
keyboardsamurai

Reputation: 701

Alright, I found out what I was doing wrong. It seems that overrides do not work when only a section of the application.conf is loaded. You cannot override the netty port with -Dakka.remote.netty.port=2553 when you configure your actor system by only loading a specific section from the application.conf like this:

val system = ActorSystem("myActorSystem",ConfigFactory.load.getConfig("client"))

application.conf file:

client{
  akka {

  log-config-on-start = on
   loglevel = "INFO"
   actor {
      provider = "akka.remote.RemoteActorRefProvider"
      include "serialization.conf"
   }

   remote {
    transport = "akka.remote.netty.NettyRemoteTransport"
    netty {
      hostname = "127.0.0.1"
      port = 2552
    }
    log-sent-messages = off
    log-received-messages = off
   }
  }
}

In this case, although you specify "client" as a subsection to load, you will still have to prepend "client" as a key to your values that will override them by using command line parameters.

Please note though, that the values in the config file will not be prepended by "client" when being loaded that way. So by using -Dclient.akka.remote.netty.port=2553 you can effectively override as you are used to.

Upvotes: 6

Related Questions