tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: How to write to a properties file
Date Thu, 12 Feb 2004 14:51:55 GMT


>what is the best way to update (write) a properties file from a servlet
>that is somewhere under /WEB-INF/src/..... ? Does this work for a
>properties file in a WAR file, too?

The servlet specification only leaves you with one standard place to
write files, the directory specified by javax.servlet.context.tempdir.
As its name implies, it's a temporary directory that the server may
clean up on shutdown.  So you don't want this.

Therefore you must specify the directory/file to write via some
configuration, e.g. a context-param or init-param in web.xml, or a JNDI
env-entry-ref if you wish.  The former is usually simpler.

But to write, you have to use the file IO APIs, and that won't work in a
packed WAR file.  It'll be OK in an exploded WAR file, but you probably
don't want to require your users to expand your WAR file.

One possible alternative is to have the properties file outside the
webapp (or better yet, change from properties file to a database?), and
configure the location of the file using one of the above approaches.
That way you can still deploy a packed WAR, write/update the properties
file, and (if you use the JNDI approach) the server admin can control
the location of the file.

Yoav Shapira

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message