0

I have a Java Web project, and I'm using Maven with the "src/main/resources" and "src/main/java" folders as the default source folders. The project is actually a RESTful web service and I use Jersey to work with REST resources and api calls.

There's a call in the api (used for testing) that exports some images and xml files (using Photoshop Scripting), uses these xml files to insert data in the DB and then return a success message to the client. After that, the client should be able to get these images using the api.

The problem is that I'm currently exporting the images and xml files to the src/main/resources folder, and the server (Tomcat) only has access to these new files if I clean/republish or restart it, and I guess I can't do that by code. In addition, the database can't be updated since the server can't access the new exported xml files.

Because of that, I tried a different approach, which was putting the images and xml files in the webapp folder of the deployed resources (along with the web pages). It worked as the server didn't need to restart to read the new files. However, in this case I'm using absolute paths to access the xml files in order to update the DB. I searched how to access files in the webapp folder using relative paths, but didn't find anything.

  • So, first of all, which of the above solutions is the best one to use?

  • If exporting the files to the resources folder is better, how do I access the new files without restarting the server?

  • If putting the images/xml files in the webapp folder is better, how do I access them using relative paths?

P.S.: When I export the images and xml files, I use absolute paths in the photoshop script to put them either in the src/main/resources folder or in the webapp folder.

  • The source folder is not deployed to your server (i hope), the webapp folder isn't a good location too, because it might be deleted on another deployment. You should always divide application and data. So just define an external directory where your server can read/write data. – Stefan Feb 25 '14 at 11:12
  • http://stackoverflow.com/questions/2663204/how-to-store-a-file-on-a-serverweb-container-through-a-java-ee-web-application – Salil Feb 25 '14 at 14:16
  • @Stefan, thanks for the reply. I don't know why I thought it was a good idea to put these files inside the project. It makes more sense to export them to an external directory, and that's what I'm gonna try to do now. And as I said, this is just a test feature. I have an Amazon bucket running for storing the exported images, I just don't want to use it for testing (it takes a lot of time to upload and refresh the files). – Renan Pinto Feb 25 '14 at 15:29
  • @Salil, thanks for the reply. It also makes sense to put these files in a DB, but that's what those xml files are for. I use the xml data to populate my tables, then I can just throw the xml files away. I think that having them in an external directory is the way to go. – Renan Pinto Feb 25 '14 at 15:32
  • @Stefan Your idea worked just fine for me. Would you mind posting your comment as the answer so I can accept it? Thanks. – Renan Pinto Feb 25 '14 at 19:19

1 Answers1

2

The source folder is not deployed to your server (i hope), the 'webapp' folder isn't a good location too, because it might be deleted on another deployment. You should always divide application and data. So just define an external directory where your server can read/write data.

Stefan
  • 11,176
  • 5
  • 40
  • 62