permaculture playing cards*
The moose likes Tomcat and the fly likes writing files during deployment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "writing files during deployment" Watch "writing files during deployment" New topic
Author

writing files during deployment

michael echavez
Greenhorn

Joined: Feb 07, 2005
Posts: 18
Hi,

I created a web application deployed in tomcat that basically writes a file under one of its folders (say, C:/tomcat5.5/webapps/mywebapp/temp) the first time it is used by a client and reads it to retrieve dynamic content (texts). I successfully ran and tested the app on my computer and two other computers (each one having its own fresh installation of tomcat where I deployed the application for testing). Now the odd thing is that when I sent the war file to my colleagues, two of them told me that the file cannot be written. We have the same version of tomcat. Could this be an issue with tomcat? Is there an option that I have to set so that files are allowed to be written during deployment?

Michael
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Webapps can be deployed several ways with Tomcat.
When you were developing it, you probably ran it as a directory structure on the file system. When it's run like this, getRealPath works and you can write to the directory structure of the webapp.

If you deploy the app as a packed war archive, getRealPath will return null and there won't be a file structure for it to write to.

Ask your colleagues to deploy it by placing the war file under the tomcat/webapps directory. Tomcat, by default, will unpack the war file when you deploy it this way.

This also could be a case of file permissions or, depending on how you determined the path a simple case of trying to write to a directory that doesn't exist.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
michael echavez
Greenhorn

Joined: Feb 07, 2005
Posts: 18
Thank you Ben for replying! I just resorted to *not* writing the file at all and just store the content as a String and retrieve it on demand. This makes the code a lot shorter and simpler. Thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing files during deployment