Bryan Young
Bryan Young

Reputation: 654

Adding static file to classpath in Play Framework

I have the need to add a static html file to my app/controllers directory in a Play app. I won't be serving it or anything. I need to use it as a template for creating a document on the server side. I'm loading it from the classpath.

Everything works fine if run from IntelliJ IDEA (which seems to copy the file to the target directory for me). Play doesn't do this on its own when run from the command line. I assume there's a configuration somewhere allowing me to specify file types to be copied to the target dir, but I can't find it anywhere.

Upvotes: 0

Views: 2431

Answers (1)

ndeverge
ndeverge

Reputation: 21564

In order to have the resource in your classpath, add your file in the conf folder.

Then to retrieve it with Java :

String relativePath = "/path/to/my/file";
Url myFile = play.Play.application().resource(relativePath)

See http://www.playframework.com/documentation/2.3.x/api/java/play/Application.html#resource(java.lang.String)

Upvotes: 4

Related Questions