-
Regarding WAR files
Hi All,
I have developed a project for my client which involves uploading images. At present I am storing images within the project, i.e it gets stored within the build folder inside a folder named images. While working in my machine with Netbeans IDE, if I clean and rebuild the project, the images which I had uploaded before also gets deleted. I could actually store the images in a folder outside the project, but it doesn't make sense since while hosting with an external hosting server (like eukhost), I have been allocated a space and I doubt if I could store those images wherever I wish to. This was the problem I faced while developing the project within my machine. So the solution I could find out was never to clean the project.
But now while hosting, if I make slight changes to any files, I will have to deploy a new WAR file. And since my images are stored within the build folder, every time I create a new WAR file, the existing images would get deleted, since for creating the war, don't we have to clean and build the project (this is what I have read somewhere).
I hope you have understood my question. So what is the best solution for me to deploy new war files, so that the images that have been previously uploaded doesn't get deleted.
Thanks in advance.
-
probably store the images inside a folder within the user's home folder. your hosting provider runs tomcat as a user, that should have a home directory and be able to write stuff to a folder you could create and maintain images into there ?
for example, an "images" folder inside the user's home folder, where ever this happens to be.
Code:
File imagesFolder = new File(System.getProperty("user.home"), "images");
System.out.println("images folder is : " + imagesFolder);
This would solve the problem for both local development and deployment.
Another idea, might be to store the image files into a database, which is also not inside the application folder.
The only thing that should be stored in the application folder is the application, or anything transient or computed that you can expect to lose when redeploying the application.
-
Thanks for your reply. Any ways, I have found an easier way to solve this. I would be storing the images in a folder just outside by web app project. and the path for this would be specified in the Context docbase within Tomcat server.xml.
For example, if I am storing the images in D:\images. my server.xml would look like this:
<Context docBase="C:/home/cPanel/public_html/PropertyImages" path="/FinalPropertySolutions/Admin/PropertyImages" />
where the path is the relative position from where I get the images. so wherever I specify this path, the images would actually be taken from D:\images.
This would ideally solve my problem because if I need to further deployments, I need not take care of these images and my deployment would be faster.
Anyways thanks for your suggestion.