Play Framework custom resources: how to copy to ta

2019-04-28 04:36发布

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

3条回答
戒情不戒烟
2楼-- · 2019-04-28 04:56

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.

查看更多
地球回转人心会变
3楼-- · 2019-04-28 04:59

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

getClass.getResourceAsStream("/file.csv")

Check out this blog post.

查看更多
Fickle 薄情
4楼-- · 2019-04-28 05:06

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
查看更多
登录 后发表回答