Cannot load application.conf with typesafehub/config library

5,079 views
Skip to first unread message

Jacobus Reyneke

unread,
Mar 28, 2012, 3:10:54 AM3/28/12
to akka...@googlegroups.com
Hi,

I'm using the same config library (https://github.com/typesafehub/config) that Akka uses to load configuration settings, but can't get it to work.

Here's my code:

import com.typesafe.config._

 val conf = ConfigFactory.load()
   println("Server port: " + conf.getString("devserver.port"))

Here is the application.conf file:

devserver {
   port = 80
}

I'm using IntelliJ Idea as dev tool, but also tried sbt from the command line. In both cases I get:
Exception in thread "main" java.lang.ExceptionInInitializerError
    at MSG.main(MSG.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'devserver.port'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:126)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:148)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:119)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:157)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:199)
    at MSG$.<init>(MSG.scala:48)
    at MSG$.<clinit>(MSG.scala)
    ... 6 more

Other config info prints out fine with println(conf.root.render), but my devserver stuff is not among it. Maybe it's a classpath issue, but I tried placing the application.conf in the project root folder and all other source folders and it still would not pick it up. Any idea where it will start looking for the file by default in a simple sbt project? (if this is the problem)

As a test I cloned the typesafe/config project from github, but it has has many broken dependencies when trying to do sbt update.

Regards,
Jacobus

Patrik Nordwall

unread,
Mar 28, 2012, 11:42:04 AM3/28/12
to akka...@googlegroups.com
It's a classpath issue. ConfigFactory.load looks for application.conf in the classpath.

For sbt you should place it in src/main/resources/

I'm not sure about IDEA but I think there is an option to copy certain file types to the build output. Otherwise just add src/main/resources/ to the classpath.

/Patrik
--
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/-/XJDnoJ-n9AQJ.
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.

Sergey Malov

unread,
Mar 28, 2012, 12:30:18 PM3/28/12
to akka...@googlegroups.com
Normally if configuration file location is not in a standard place (or with multiple configs), in Intellij I set option "-Dconfig.file=<full/path/to/config>" option on "VM options" string in "Application" dialog - to run my app through it, and it works.
Otherwise, add location to a classpath, as Patrik suggested.

Sergey 
 
Reply all
Reply to author
Forward
0 new messages