I’m working on a GWT app where I’m retrieving a file from a web service and then returning the URL via RPC for the UI to display. The file is being created/saved in a folder called documentFiles:
File newFile = new File("documentFiles", doc.getFilename());
newFile.getParentFile().mkdirs();
When I run the app locally in GWT dev mode, this folder is created where I expect, in the war directory, so I can access it at host:8080/[base url]/documentFiles.
However, when I run it on glassfish (on Windows) the folder is being created under ...\glassfish\domains\domain1\config\documentFiles.
I want and expect it to be under ...\glassfish\domains\domain1\applications\[app name]\documentFiles
I hope this makes sense. How can I specify that the file be created under the application folder? Appreciate any help. Thanks.
Accessing files from web applications via direct File IO is generally a bad idea and a bad design. How are you making sure that only one running instance is accessing the file? Think about your app used by hundreds of concurrent users, possibly running on multiple Glassfish instances. How about transaction handling? Etc.
If you have to access files you should do that in the “standard” way, using a resource adapter specifically written for this purpose. The last time I checked (~2 years ago) there was a File Resource Adapter for Glassfish in beta state – it was usable, but not very reliable. I remember we had some problems with the transaction handling part. It could be in a better shape by now…
You should probably be better off by forgetting file IO, and solving the problem in alternate ways (eg. communicating via database or JMS). We were forced to use files because of a legacy API, if you have no such restrictions then don’t do this.