how to load external configuration file in akka 2.0 ?

11,688 views
Skip to first unread message

Sergey Malov

unread,
Mar 21, 2012, 10:44:22 AM3/21/12
to akka...@googlegroups.com
I have external configuration file I'm trying to load before starting my application, it is sourced inside the app as:
val conf = ConfigFactory.load("custom.conf");

It has some updated akka {} settings (debug-related) and some application specific settings.

I'm starting app as:
java -Dconfig.resource=<path>/custom.conf -jar Application.jar

I tried relative <path>, absolute <path> - nothing works, I'm getting error:

Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:115)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:135)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:140)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:108)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:146)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:188)
at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:116)
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:424)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:103)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:89)
at com.mdialog.linear_stream_manager.LinearStreamManager$delayedInit$body.apply(App.scala:9)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at com.mdialog.linear_stream_manager.LinearStreamManager$.main(App.scala:7)
at com.mdialog.linear_stream_manager.LinearStreamManager.main(App.scala)


Anything I'm doing incorrectly ?

Thanks,

Sergey


Henrik Engstrom

unread,
Mar 21, 2012, 11:46:45 AM3/21/12
to akka...@googlegroups.com
Hey Sergey,
Can you please enlighten me with the version of Akka you're using + the config file you're trying to load.
That would help me investigate what your issue is.
Thanks
//Henrik



--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.




--
Henrik Engstrom
Typesafe - The software stack for applications that scale
Twitter: h3nk3

Akka Team

unread,
Mar 21, 2012, 11:54:47 AM3/21/12
to akka...@googlegroups.com
Sorry, just read the subject line and it says Akka 2.0... My bad.

Can you try the following:
 java -Dconfig.file=<path>/custom.conf -jar Application.jar

Also val conf = ConfigFactory.load() should be enough.
If you do not specify a specific config when starting an ActorSystem it will use what you specified as a parameter, i.e. you do not have to explicitly give it a config.

HTH
//Henrik
--
Akka Team
Typesafe - The software stack for applications that scale
Blog: letitcrash.com
Twitter: @akkateam

Sergey Malov

unread,
Mar 21, 2012, 12:12:54 PM3/21/12
to akka...@googlegroups.com
Tried all possible permutation of you suggestions, unfortunately, effect is the same ;)

Sergey Malov

unread,
Mar 21, 2012, 2:14:43 PM3/21/12
to akka...@googlegroups.com
For some reason, my reply to both of your replies didn't get anywhere, so I repeat it.
I tried your suggestions, they didn't work, produced the same result.
custom.conf is posted below. It works fine when it is in main/resource directory and/or included in a final jar file. However it has to be externalized thus all the problems.

include "application"

akka {
  loglevel = "DEBUG"
  stdout-loglevel = "DEBUG"
  log-config-on-start = off
    debug {
      receive = on
      autoreceive = off
      lifecycle = off
      fsm = off
      event-stream = on
    }
}

com {
    mdialog {
        application_manager {
            update_address = "tcp://0.0.0.0:5555"
            uploader_address = "tcp://0.0.0.0:6666"
On 2012-03-21, at 11:54 AM, Akka Team wrote:

Sergey Malov

unread,
Mar 21, 2012, 11:59:39 AM3/21/12
to akka...@googlegroups.com
I'm using akka 2.0.
File is posted below. It is sourced fine if I keep it in main/resources directory, application settings are loaded correctly and accessible.

include "application"

akka {
  loglevel = "DEBUG"
  stdout-loglevel = "DEBUG"
  log-config-on-start = off
    debug {
      receive = on
      autoreceive = off
      lifecycle = off
      fsm = off
      event-stream = on
    }
}

com {
    mdialog {
        application_manager {
            update_address = "tcp://0.0.0.0:5555"
            uploader_address = "tcp://0.0.0.0:6666"
        }
    }
}


Patrik Nordwall

unread,
Mar 22, 2012, 2:38:56 AM3/22/12
to akka...@googlegroups.com
-Dconfig.file is the way to specify an external file to load. I use it and it works fine. It is described here: https://github.com/typesafehub/config/blob/master/README.md

When you use -Dconfig.file you should use ConfigFactory.load()

I would recommend that you use plain ActorSystem("MySystem")
that will load application.conf from classpath by default, but if you have specified -Dconfig.file that file will be used instead.

If that doesn't work you should share the failing code you use for loading the config.


BTW, there is a bug in the documentation regarding the debug config properties.

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--

Patrik Nordwall

Typesafe The software stack for applications that scale

Twitter: @patriknw


Havoc Pennington

unread,
Mar 23, 2012, 6:05:40 PM3/23/12
to akka...@googlegroups.com
Hi,

Not sure if you figured this out already (I didn't see the thread
until now), but in case it helps someone coming along later,

On Wed, Mar 21, 2012 at 10:44 AM, Sergey Malov <sma...@mdialog.com> wrote:
> I have external configuration file I'm trying to load before starting my application, it is sourced inside the app as:
>        val conf = ConfigFactory.load("custom.conf");
>

detailed docs are at
http://typesafehub.github.com/config/latest/api/com/typesafe/config/ConfigFactory.html

if necessary you could also refer to
https://github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/ConfigFactory.java
though please let me know if the docs are missing important info.

The config.resource, config.file system properties only apply if you
are using load() with no arguments:
http://typesafehub.github.com/config/latest/api/com/typesafe/config/ConfigFactory.html#load%28%29

If you specify a filename like custom.conf, then it is loaded
unconditionally and those system properties are not used.

> Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'

What this error means (most likely) is that "reference.conf" from the
Akka jar is not in the Config that you're providing to the
ActorSystem.

If you get desperate, in the latest version of the config lib you can
do "-Dconfig.trace=loads" and it will log each config file loaded to
stderr. To enable this you would have to patch and rebuild Akka, with
the patch at https://github.com/akka/akka/pull/375 which is a fairly
major undertaking. It's probably easier to make some simple test code
showing how you load your config here for us to debug, as Patrik says.

I don't think it's possible to use any flavor of ConfigFactory.load()
without getting reference.conf, assuming that the akka jar is on your
classpath, so my guess is that your problem is not related to the
custom.conf filename?

Does the following (untested) program work for you?

object TestApp extends App {
val conf = ConfigFactory.load()
val system = ActorSystem("MySystem", conf")
// maybe start some actor here , not sure if you need to
system.awaitTermination()
}

If that program works, can you modify it to be more like your real
program until it breaks, then send us the resulting test case?

Havoc

G J

unread,
Mar 24, 2012, 11:47:08 AM3/24/12
to Akka User List
I'm struggling with this as well.

My project uses Akka but also has a fairly large configuration
component of it's own. There is a UAT testing environment and
production environment. Both akka, and the project configuration files
need to be modified for each environment. I therefore have:

reference.conf:
UAT:
akka
myproject
Production:
akka
myproject

application.conf:
UAT:
akka
myproject
Production:
akka
myproject

Reading the documentation, I did every System.setProperty imaginable,
but nothing worked. [My understanding of the framework is obviously
shot.]

Is this at all possible?

Thanks.

On Mar 23, 6:05 pm, Havoc Pennington <h...@pobox.com> wrote:
> Hi,
>
> Not sure if you figured this out already (I didn't see the thread
> until now), but in case it helps someone coming along later,
>
> On Wed, Mar 21, 2012 at 10:44 AM, Sergey Malov <sma...@mdialog.com> wrote:
> > I have external configuration file I'm("/tmp/myConfig.conf) trying to load before starting my application, it is sourced inside the app as:
> >        val conf = ConfigFactory.load("custom.conf");
>
> detailed docs are athttp://typesafehub.github.com/config/latest/api/com/typesafe/config/C...
>
> if necessary you could also refer tohttps://github.com/typesafehub/config/blob/master/config/src/main/jav...
> though please let me know if the docs are missing important info.
>
> The config.resource, config.file system properties only apply if you
> are using load() with no arguments:http://typesafehub.github.com/config/latest/api/com/typesafe/config/C...
>
> If you specify a filename like custom.conf, then it is loaded
> unconditionally and those system properties are not used.
>
> > Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
>
> What this error means (most likely) is that "reference.conf" from the
> Akka jar is not in the Config that you're providing to the
> ActorSystem.
>
> If you get desperate, in the latest version of the config lib you can
> do "-Dconfig.trace=loads" and it will log each config file loaded to
> stderr. To enable this you would have to patch and rebuild Akka, with
> the patch athttps://github.com/akka/akka/pull/375which is a fairly

Patrik Nordwall

unread,
Mar 24, 2012, 3:23:26 PM3/24/12
to akka...@googlegroups.com
There is at least one thing I don't understand of your problem description. Do you try to have different reference.conf for UAT and Prod? Shouldn't those differences only be in the application.conf used in the specific environment?

/Patrik

G J

unread,
Mar 24, 2012, 5:21:52 PM3/24/12
to Akka User List
In one form of UAT testing, data is read from zipped files, but is
otherwise from an IP address in production. The source of those files
do not change and would be part of a reference configuration.

My thinking is that the reference/application dichotomy is overkill.
My configurations are no where near as big to warrant that type of
solution.

The boost in using HOCON over JSON is benefit enough.

Thanks, and thanks for responding.
> >> the patch athttps://github.com/akka/akka/pull/375whichis a fairly

Havoc Pennington

unread,
Mar 25, 2012, 3:44:45 PM3/25/12
to akka...@googlegroups.com
Hi,

>   reference.conf:
>        UAT:
>           akka
>           myproject
>        Production:
>           akka
>           myproject

I don't understand your notation here;
- do you mean you have one reference.conf with sections
uat{ akka{} myproject{} } production{ akka{} myproject{} }
or do you mean you have four reference.conf?
- why do you have a reference.conf at all for akka? reference.conf
are the "factory defaults",
you should be able to put everything in application.conf

> Reading the documentation, I did every System.setProperty imaginable,
> but nothing worked.

Note that the system properties are cached the first time any config
is loaded. So System.setProperty will only work if you do it before
any config is ever loaded. However there shouldn't be a need to
System.setProperty because in code you can just use a different
ConfigFactory static method and load the config that way. The property
is only needed to avoid writing code.

Can you explain more what problem you are having, though? What error
do you see and what are you expecting?

Can you make the short test case I described in the email you quoted,
showing the problem? It isn't clear enough to me what you or the
original poster are doing in your code so it's hard to give
suggestions.

Havoc

G J

unread,
Mar 26, 2012, 9:44:15 AM3/26/12
to Akka User List
Havoc,

I'd like to drop this as I have moved on, and did not get near to
implementing what I (thought) I wanted; which in hindsight may not
have been the right way to begin with.

At the risk of sounding ignorant, I meant four reference
configurations. Consider UAT: There would be a reference.conf for akka
that would contain site wide default akka settings. Individuals would
only require custom setting that deviate from the site wide settings.
Our overall system is configured using the settings in myproject.

Repeat for production which is a different environment.

This is already becoming configuration hell and doesn't seem worth the
investment.

Thanks for responding.

bradford

unread,
Apr 22, 2012, 3:57:27 PM4/22/12
to akka...@googlegroups.com
I'm looking to load an external config file as well.  I did not have any lucky adding an external config directory to my classpath.  If I use -Dconfig.file=/path/to/file.conf, then it reads the file, but it seems this becomes the only configuration file it uses.  I want to maintain resources/application.conf and have an additional external config file.  That way I can fallback to application.conf with some stuff the user doesn't care to think about when they configure the application.  Is there anything I'm missing?

√iktor Ҡlang

unread,
Apr 22, 2012, 5:33:01 PM4/22/12
to akka...@googlegroups.com
Add a fallback to application.conf?

Cheers,


On Sun, Apr 22, 2012 at 9:57 PM, bradford <finge...@gmail.com> wrote:
I'm looking to load an external config file as well.  I did not have any lucky adding an external config directory to my classpath.  If I use -Dconfig.file=/path/to/file.conf, then it reads the file, but it seems this becomes the only configuration file it uses.  I want to maintain resources/application.conf and have an additional external config file.  That way I can fallback to application.conf with some stuff the user doesn't care to think about when they configure the application.  Is there anything I'm missing?

--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To view this discussion on the web visit https://groups.google.com/d/msg/akka-user/-/zWbnPAYmyMIJ.

To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

Patrik Nordwall

unread,
Apr 23, 2012, 2:13:03 AM4/23/12
to akka...@googlegroups.com


22 apr 2012 kl. 21:57 skrev bradford <finge...@gmail.com>:

I'm looking to load an external config file as well.  I did not have any lucky adding an external config directory to my classpath.  If I use -Dconfig.file=/path/to/file.conf, then it reads the file, but it seems this becomes the only configuration file it uses.  I want to maintain resources/application.conf and have an additional external config file.  That way I can fallback to application.conf with some stuff the user doesn't care to think about when they configure the application. 

Are you developing a library?
Then your library should define default values in its own reference.conf and application.conf (or other specific file) can be used by the application.

Is there anything I'm missing?

--

Havoc Pennington

unread,
Apr 23, 2012, 9:12:49 AM4/23/12
to akka...@googlegroups.com
Hi,

At the top of /path/to/file.conf, add the line

include "application.conf"

Then anything after that line will override application.conf. Or if
you want file.conf stuff to be overridden by application.conf, put the
include at the bottom instead of the top.

As Patrik says if you are making a library and just defining default
settings, the intended approach is to create a reference.conf

In future versions (not in Akka 2.0) there's some more flexibility
with include statements, which may also be useful:
https://github.com/typesafehub/config/blob/master/NEWS.md

Havoc

bradford

unread,
Apr 23, 2012, 8:52:04 PM4/23/12
to akka...@googlegroups.com
Thanks, Havoc.  This works just as needed. 

Was I mistaken, though, to expect Akka to pickup up the config file in the directory that I manually added to the classpath?

Havoc Pennington

unread,
Apr 24, 2012, 8:30:18 AM4/24/12
to akka...@googlegroups.com
Hi,

On Mon, Apr 23, 2012 at 8:52 PM, bradford <finge...@gmail.com> wrote:
> Was I mistaken, though, to expect Akka to pickup up the config file in the
> directory that I manually added to the classpath?
>

-Dconfig.file specifies an alternative to application.conf, so if you
specify -Dconfig.file, there's no attempt to load any application.conf
unless you include it yourself.

But reference.conf is loaded in both cases.

The "Standard behavior" section in
https://github.com/typesafehub/config/blob/master/README.md goes into
some detail.

Havoc

Jamie Allen

unread,
May 30, 2012, 6:54:43 PM5/30/12
to Akka User List
I also ran into this issue using OSGi and trying to load an
ActorSystem. Havoc pointed out to me that it was likely a ClassLoader
issue, and he was right. By explicitly using the
ActorSystem.getClass.getClassLoader, I was able to get the
configuration I needed with the Akka settings.

On Apr 24, 5:30 am, Havoc Pennington <h...@pobox.com> wrote:
> Hi,
>

Jun Ma

unread,
Feb 28, 2017, 4:18:26 AM2/28/17
to Akka User List
What the hack does this mean " it will use what you specified as a parameter"? Which parameter? You meant the parameter assigned by the "-D"?
Are you Akka guys really programmers? Your doc and product line control sucks!
What do you guys expect users to keep up with various migrations of Akka?! 
You guys think the maintenance comes for free for users?! 

JM

Patrik Nordwall

unread,
Feb 28, 2017, 2:27:48 PM2/28/17
to Akka User List
Hi JM,

You are throwing out some insulting comments that I will not accept. Can you instead explain what you are having trouble with in a constructive way and I'm sure someone will try to help or understand the need for improvements.

Regards,
Patrik
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.

Justin du coeur

unread,
Feb 28, 2017, 3:55:24 PM2/28/17
to akka...@googlegroups.com
Coming into this *not* as a member of the Akka Team, but as a heavy customer -- this is out of line.  I won't claim it's perfect, but both Akka the system and the supporting documentation are good in the grand scheme of things, and always getting better.

This sort of rudeness is inappropriate (all the moreso if you're getting it for free)...

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+unsubscribe@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.

Guido Medina

unread,
Mar 1, 2017, 4:26:12 AM3/1/17
to Akka User List
Jun Ma,

I honestly don't know what kind of universe you live, Akka or any other open source toolkit which are "free" have nothing to do with comunism,
and yes, I know about comunism because I lived the 1st 24 years of my life in Cuba.

Free in the sense that you don't have to spend money, but is not really free, you have to spend time, you have to do your homework,
or pay a better professional that has the patience to at least spend the necessary time to understand,
your first reaction which is to insult an awesome and mostly busy team tells me you lack both,

I started using Akka 2 years ago and I have been able to complete two projects with complex configurations, fallbacks and all sort of environments,
test, uat and production, and trust me Akka can have a bug or two but when found they are fixed by them or the community in almost an instant,

the config API used by Akka I can tell you is bug free, it has been in the same version for a year you know why?, because it does what it says it does,
go and read its documentation, understand first how to use it, its documentation is great and extremely easy to understand.

And good luck, personally I would had given you a different answer to your insult but hey, this is a community not a personal thing.

Guido.

Guido Medina

unread,
Mar 1, 2017, 4:42:45 AM3/1/17
to Akka User List, sma...@mdialog.com
Hi Sergey,

I have micro-services that run as Java main and the passed command line parameter is where my config file is located,
I also fallback to an internal config (static.conf) which is part of a jar file, example below:

final Config config = ConfigFactory.parseFile(new File(args[0])).withFallback(ConfigFactory.parseResources("static.conf")).resolve();

The resolve call is very important if you need to use variables and resolve the final values once all your configurations are parsed,
by parsed I mean syntactically, the final result is computed by the resolve() call.

HTH,

Guido.
Reply all
Reply to author
Forward
0 new messages