danielz danielz -4 years ago 86
Scala Question

Get root folder in the Play Framework during production?

I am working on a project where I have to save some temporary user generated files on the file system. In my dev environment I created a folder called

in my root folder and user relative paths to read and write from the folder.

However when I run the server in production using
/.activator start
. The framework tries to read from

I even tried using
but I keep getting the same path.

Is there a way to get the root folder in production?

Thank you

Answer Source

You are getting correct root folder. The sense of start command is to verify how your application will run in production. So it build application, like you will do when you will push it to prod. And then "deploy it to prod" - unpack it to the target/universal/stage folder and run application from that folder. So target/universal/stage is your correct root folder.

Take in to attention - start command is deprecated:

[warn] The start command is deprecated, and will be removed in a future version of Play.

[warn] To run Play in production mode, run 'stage' instead, and then execute the generated start script in target/universal/stage/bin.

[warn] To test your application using production mode, run 'testProd' instead.


You need to add to the build.sbt next code

mappings in Universal ++=
  (baseDirectory.value / "usr" * "*" get) map
    (x => x -> ("usr/" + x.getName))

This will say to sbt to add your "usr" folder to the "production package" (stage). Take in to attention - it will not "link", it will hard copy usr folder to the target/universal/stage so you will have target/universal/stage/usr that is copy of usr just before you run command start

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download