Search code examples
tomcatservletsweb.xmltomcat8

how to modify web.xml permanently from servlet


is it possible to modify web.xml permanently from servlet so that if any context-param (or init-param or anything else) value is changed at runtime, this change also reflects even after restarting the server ? I am currently using tomcat 8.


Solution

  • It is really bad practice to do so - if only because you'll have to keep track of your changes when you update an application.

    If you have such requirements, you should save your configuration elsewhere, e.g. in a database or in some file outside of your webapplication, so that you can deploy your webapplications without changes but still read the configuration of the system that you're currently running in.

    Don't forget to include that configuration file/database content in your backup.

    Also, AFAIK tomcat (in its default configuration) monitors web.xml and will reload the application (e.g. shut it down and restart) once it detects changes to web.xml - this might not be the behaviour you expect. And not to forget that tomcat might be configured to just deploy a WAR file without unpacking it - you might not even have a web.xml file on disk. It could still reside within the WAR file (this is a possible configuration, just not the standard)