Access configuration resources in Scala IDE
Asked Answered
P

1

12

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)
Proleg answered 27/12, 2012 at 19:26 Comment(0)
V
16

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

Vitiate answered 27/12, 2012 at 20:44 Comment(2)
That did the trick. Thank you kindly. I'll look into sbteclipse.Proleg
Put the settings in ~/.sbt/0.13/build.sbt to set for all SBT projects.Entirely

© 2022 - 2024 — McMap. All rights reserved.