scala - Access data files in production play server -
i have play in scala application directory structure looks this:
- app
- conf
- data <- added manutally
- logs
- project
- public
- target
- test
the data directory have manually added, contains number of json files application depends on. getting hold of them in code seems easy enough, , works when run "play run". code use reference them:
val projectroot = play.application.path.getabsolutepath val statfiles = new file(projectroot + "/data/"+tier+"/usage").listfiles
however, when run "play start" nullpointerexceptions, stack trace looks this:
caused by: java.lang.nullpointerexception: null @ scala.collection.mutable.arrayops$ofref$.length$extension(arrayops.scala:192) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.mutable.arrayops$ofref.length(arrayops.scala:192) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.seqlike$class.size(seqlike.scala:106) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.mutable.arrayops$ofref.size(arrayops.scala:186) ~[org.scala-lang.scala-library-2.11.1.jar:na] @ scala.collection.mutable.builder$class.sizehint(builder.scala:69) ~[org.scala-lang.scala-library-2.11.1.jar:na]
my guess somehow in way production application setup, ability reference files in same way gets lost. that's not obvious stack trace, though... wondering if caused fact i've added data directory , not built properly, , if how resolve it.
data folder not copied default target folder.
few ways can solve are:
- move data conf folder , access using new file("conf/data" + tier +"/usage")
- sbt can add unmanaged resource directory production build with
unmanagedresourcedirectories in compile += basedirectory.value / "data"
you can read more aout on http://www.scala-sbt.org/0.13/docs/howto-customizing-paths.html
Comments
Post a Comment