play2war / play2-war-plugin

WAR Plugin for Play framework 2.x
Apache License 2.0
443 stars 71 forks source link

Access to external files from the application context #299

Closed xela85 closed 8 years ago

xela85 commented 8 years ago

Hello,

I would like to read an Excel file containing some useful data for my web application. To do it, I did that:

 File toRead = new File("data" + File.separator + "file.xlsx");

The file is in the data folder which is at the root of the project (not in app). It is correctly read after an activator dist, but seems to be excluded after a activator war command.

I have seen that it works if I add manually the data folder on Tomcat bin directory, but I find this quite ugly and would prefer having something self-contained. What if the server is not Tomcat?

Can you please point out what I did wrong?

Thanks in advance.

yanns commented 8 years ago

The war does not package the file in data. And even if the file is packaged in the war, unless you deploy the war as exploded, you cannot access it with File.

You have 3 solutions:

xela85 commented 8 years ago

I've tried the third option (exploded war) because I use an external library which requires java.io.File. It works, thank you !