Question

I'm trying to deploy my Play!Framework to Heroku but I'm having the following errors:

app[web.1]: [error] application - Error reading filename: create_user.json
app[web.1]: [error] application - Error reading filename: delete_user.json
app[web.1]: [error] application - Error reading filename: login_user.json
...

I use these .json file as schema to validate the inputs from the client. They are located under the 'app/assets/json/' directory. I guess they aren't being pushed to Heroku at all, but I don't know how to check that either.

I saw similar issues where the missing files are located under 'public' directory, so that a 'git add -A' would solve the problem:

Scala Play 2.1.0 - Assets not appearing on Heroku?

However, it does not apply to my problem.

Additional info: Play 2.2.2, MongoHQ, server-side only.

Thank in advance!

Edit:

The stacktrace shows me that the application is looking for the json files at

/app/target/universal/stage/app/assets/json/

where /app corresponds to the default root of the application in the Heroku dyno (checked with 'heroku run bash'), /target/universal/stage is defined in my Procfile, and the remaining path /app/assets/json is the correct hierarchy in my development environment. The path above doesn't exist on Heroku, obviously.

I'm using the following method to get the json files:

Play.application().getFile("app/assets/json/create_user.json");

Works in development environment, but not in production. I don't know how to make these files accessible in production as well.

Was it helpful?

Solution

It turns out that Play! does not allow such operation in production mode

Play.application().getFile("app/assets/json/create_user.json");

According to James Roper, here, "It's bad practice in Play to rely on the filesystem".

Instead, one should provide the file in either 'conf' of 'public' folders and load them as resources. These files are embedded in the packaged application.

Since his solution is in Scala, and I have found some solutions with the old Play!Framework 1.X, I decided to post what actually worked for me with Play! 2.2.2 and Java 1.7:

Play.application().classloader().getResourceAsStream("json/create_user.json");

with my .json files located at 'conf/json'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top