Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework custom resources: how to copy to target?

I have a .csv file, that must be read on application startup.

How can I make play to copy this file to target (to "run" or "start" it).

I'm trying to access this file in Global-class with Global.class.getResourceAsStream("/file.csv"), but the result is always null.


OK - thanks. I have managed it with my file in conf/ressources folder and loading it with /ressources/file.csv path

like image 464
vadimiron Avatar asked Jul 06 '12 06:07

vadimiron


People also ask

How do you set content type explicitly on play?

Changing the default Content-Type Will automatically set the Content-Type header to text/plain , while: JsonNode json = Json. toJson(object); Result jsonResult = ok(json); will set the Content-Type header to application/json .

What is activator in play framework?

The activator command can be used to create a new Play application. Activator allows you to select a template that your new application should be based off. For vanilla Play projects, the names of these templates are play-scala for Scala based Play applications, and play-java for Java based Play applications.

How do I run a play framework?

To run a Play application: Create a new Run Configuration – From the main menu, select Run -> Edit Configurations. Click on the + to add a new configuration. From the list of configurations, choose “sbt Task”


2 Answers

You can put it in several places:

  • either in the app folder
  • either in the conf folder: I'd go for this one, by creating a conf/ressources folder
like image 118
ndeverge Avatar answered Sep 22 '22 03:09

ndeverge


You can create a resources folder in your conf folder, put your file there, and then create an InputStream by calling

Play.classloader.getResourceAsStream("resources/file.csv");

Note that you should not start the path with a /, because then the application will not be able to resolve the path and throw a java.lang.ExceptionInInitializerError: null on startup.

like image 34
notan3xit Avatar answered Sep 23 '22 03:09

notan3xit