Play Framework user resources: how to copy to target?

I have. A CSV file that must be read when the application starts.

How to make a game to copy this file to the target ("run" or "run").

I am trying to access this file in a global class using Global.class.getResourceAsStream("/file.csv") , but the result is always zero.


OK thanks. I managed my file in the conf / ressources folder and downloaded it from /resources/file.csv path

+6
source share
3 answers

You can put it in several places:

  • either in the app folder
  • either in the conf folder: I would go for it by creating the conf/ressources
+3
source

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

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

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

+3
source

You can put it in the test/resources/file.csv folder in the test folder of the playback project. Then you can access it in scala using

 getClass.getResourceAsStream("/file.csv") 

Check out this blog post .

0
source

Source: https://habr.com/ru/post/919826/


All Articles