title: Serving static /public/ file from Play 2 Scala controller
body: <p>What is the preferred method to serve a static file from a <a href="http://playframework.org" rel="nofollow">Play Framework 2</a> Scala controller?</p>
  
  <p>The file is bundled with my application, so it's not possible to hardcode a filesystem absolute <code>/path/to/the/file</code>, because its location depends on where the Play app happens to be installeld.</p>
  
  <p>The file is placed in the public/ dir, but not in app/assets/, because I don't want Play to compile it.</p>
  
  <p>(The reason I don't simply add a route to that file, is that one needs to login before accessing that file, otherwise it's of no use.)</p>
  
  <p>Here is what I've done so far, but this breaks on my production server.</p>
  
  <pre><code>object Application ...
  
    def viewAdminPage = Action ... {
      ... authorization ...
      val adminPageFile = Play.getFile("/public/admin/index.html")
      Ok.sendFile(adminPageFile, inline = true)
    }
  </code></pre>
  
  <p>And in my <code>routes</code> file, I have this line:</p>
  
  <p><code>
  GET   /-/admin/                 controllers.Application.viewAdminPage
  </code></p>
  
  <p>The problem is that on my production server, this error happens:<br>
  <code>FileNotFoundException: app1/public/admin/index.html</code>  </p>
  
  <p>Is there some other method, rather than <code>Play.getFile</code> and <code>OK.sendFile</code>, to specify which file to serve? That never breaks in production?</p>
  
  <p>(My app is installed in <code>/some-dir/app1/</code> and I start it from <code>/some-dir/</code> (without <code>app1/</code>) — perhaps everything would work if I instead started the app from <code>/some-dir/app1/</code>. But  I'd like to know how one "should" do, to serve a static file from inside a controller? So that everything always works also on the production servers, regardless of from where I happen to start the application)</p>