Skeptic Scribbler
Skeptic Scribbler

Reputation: 547

where to keep external files in play framework while using scala

Where should I keep external files in play framework? I tried adding it to conf folder, it didn't work. Then I added it in project folder, it didn't work either. I defined the dependency in build.scala, but that didn't work as well. That file is supposed to be used in file input stream.

Upvotes: 2

Views: 810

Answers (1)

Alex Yarmula
Alex Yarmula

Reputation: 10667

The contents of conf, including subdirectories, will be available on classpath. Then you can access it in your application.

For example, if you create a resources directory in conf and put a file in it:

 -- app
 -- bin
 -- conf
   - resources
       - myfile
 ...

Then you can get the contents as:

val stream = getClass.getResourceAsStream("/resources/myfile")
val content = io.Source.fromInputStream(stream).mkString

You can inspect what gets copied and is made available on classpath by going to <play root>/target/scala-xx/classes/.

Upvotes: 2

Related Questions