In a lift project, I put the db configurations in a file called db.properties
/src/main/resources/db.properties
And in my Boot.scala, I read it as:
val input = this.getClass.getResourceAsStream("db.properties")
println("### input: " +input)
val db = new java.util.Properties
db.load(input)
val url = db.getProperty("url")
println("#### url:" + url)
Then I start sbt:
sbt prepare-web jetty-start
The console prints some errors:
### input: null
21:48:55.906 [main] ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly
java.lang.NullPointerException: null
at java.util.Properties$LineReader.readLine(Properties.java:418) ~[na:1.6.0_27]
at java.util.Properties.load0(Properties.java:337) ~[na:1.6.0_27]
at java.util.Properties.load(Properties.java:325) ~[na:1.6.0_27]
at bootstrap.liftweb.Boot.boot(Boot.scala:21) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.
It’s strange lift can’t find the db.properties!
I’ve checked target/webapp/WEB-INF/classes, and db.properties is there! Where is wrong?
The code you posted should work – you might try
val input = getClass.getResourceAsStream("/db.properties")Alternatively you might try the built-in Lift Props meccano:
http://www.assembla.com/wiki/show/liftweb/Properties
If you use Mapper (= persistence framework that comes with Lift) you might have a look at:
http://www.assembla.com/spaces/liftweb/wiki/Mapper
If everything fails – ask the friendly lift community:
http://groups.google.com/group/liftweb
Hope that helps
Paul