Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access configuration resources in Scala IDE

Some of my colleagues use Eclipse 3.7.2 and Scala IDE 2.1 for development. I want to use typesafe's config module for applicaton configuration. I want to use the convention based default configuration location. According to the examples and documentation, the default config can be found at the following path relative to project root

/src/main/resources/application.conf

But when I run my project using Scala IDE's Scala Application loader, the SimpleConfig type is unable to load any configuration values set in this file. An alternative is to pass in a config-file system property via sbt, but I don't want to have to explicitly set this path somewhere. Can anyone point out what I'm doing wrong?

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.foo.dataservices.MyServer.main(MyServer.scala)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'bar'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:115)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:138)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:150)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:155)
    at com.typesafe.config.impl.SimpleConfig.getConfigNumber(SimpleConfig.java:170)
    at com.typesafe.config.impl.SimpleConfig.getInt(SimpleConfig.java:181)
like image 747
Sean Glover Avatar asked Dec 27 '12 19:12

Sean Glover


1 Answers

You need to add your resources folder to your java build path:

  1. Right Click on your project in the Project Explorer
  2. properties -> click Java Build Path -> select "Source" tab
  3. click "Add Folder..." and add your src/main/resources folder

update: if you are using the sbt eclipse plugin you can configure it to automatically add the resources folder to the classpath :

(from: sbteclipse docs)

EclipseKeys.createSrc := EclipseCreateSrc.Default + EclipseCreateSrc.Resource

like image 128
David Holbrook Avatar answered Oct 15 '22 13:10

David Holbrook