Separate web.xml for development and production

eclipse, java, web-applications

Solution

If you can't use the same `web.xml` during development, I would automate the build process, use two `web.xml` and bundle the "right" one at build time depending on the targeted environment as Brian suggested. But, instead of Ant, I'd choose Maven because it will require less work IMHO and it has a built-in feature called profiles that is perfect to manage environment specific stuff like here.

In other words, I'd put the build under Maven 2 and use a production profile containing a specific maven-war-plugin configuration to build a WAR containing a `web.xml` having the required security constraints. Another option would be to merge the development `web.xml` (cargo can do that) to add the security-constraints but this is already a bit more "advanced" solution (a bit more complex to put in place).

Problem

My web.xml is different in devel and production environments. For example in development environment there is no need in security constraints. Typically I deploy new application version as follows: - Export Eclipse project to WAR. - Upload WAR to the server. - Redeploy. The problem is that I have to manually uncomment security constraints in web.xml before exporting. How do you solve this problem? I also met an opinion in some articles that "web.xml is rarely changed". But how can web.xml not change if it is exported to WAR on every update? Thanks in advance!

Original source