Separate web.xml for development and production

My web.xml is different in development and production environments. For example, in a development environment, there is no need for security restrictions.

I usually deploy a new version of an application as follows:

  • Export the Eclipse project to WAR.
  • Upload the WAR to the server.
  • relocate.

The problem is that before exporting I have to manually disable the security restrictions in web.xml.

How do you solve this problem?

In some articles, I also came across the opinion that "web.xml rarely changes." But how does web.xml not change if it is exported to WAR with every update?

Thanks in advance!

+7
java eclipse web-applications
source share
6 answers

If you cannot use the same web.xml during development, I would automate the build process, use two web.xml and bundle the “right” one during build depending on the target environment, as suggested by Brian. But instead of Ant, I would choose Maven, because it will require less IMHO work, and it has a built-in profiles function, which is ideal for managing the environment, for example, here.

In other words, I would put the assembly under Maven 2 and use production profiles containing a specific maven-war-plugin configuration to build a WAR containing web.xml that has the necessary security restrictions. Another option would be to combine the development of web.xml ( cargo ) to add security restrictions, but this is already a bit of a more “advanced” solution (a bit more complicated to enter).

+10
source share

I would create a development and production deployment with various web.xml configurations. Automate their construction / maintenance through your assembly (Ant / Maven, etc.) to control common elements.

I had to solve this problem many times in the past, and in the end I wrote XMLTask - Ant plugin that allows changing XML files without using regular text replacement (this is much clever than this) and without having to mess with XSLT (this is much easier than this is). If you follow the approach described above, you can check this out. Here is the article I wrote about.

+2
source share

Assuming you were stuck with the idea of ​​modifying web.xml before deploying to production, then my likely approach was to start developing web.xml with a simple XSL transform that “embellished” web.xml your production elements, such as constraints security. Assuming you can intercept this step in your build process, then a web.xml ready for release should appear during the export process.

However, it’s usually a good idea not to have different web.xml on Wednesdays, this will invalidate your testing. Having the same value in all environments will reduce the risk of errors only in your work environment.

0
source share

I converted the project to be created using ant . The starting point was only this build.xml http://tomcat.apache.org/tomcat-6.0-doc/appdev/build.xml.txt

In the above assembly, there is no copy function in another web.xml (based, for example, on the property specified at creation), but you will learn how to do this when you enter ant a little, it should be quite easy.

As a good side effect, deploying to a remote tomcat is now just a couple of clicks from Eclipse instead of Export-> war and manually copying it to the server.

0
source share

I would add the necessary infrastructure to create a mechanical assembly using ant or maven.

When this is done, you can create a mechanical assembly for two purposes: one for dough and one for production.

However, you should seriously consider testing the same code as in your production. You will be bitten differently.

0
source share

I believe that the only war that works in several environments is an excellent solution than baking a new one with the profile option on dev, qual and prod. This is very annoying, there is no better mechanism for getting environment variables directly in web.xml without using a library like spring.

One of the solutions for configuring the web.xml environment, given that the environment settings are related to filter initialization parameters, such as:

 <filter> <filter-name>CAS Filter</filter-name> <filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name> <param-value>https://<foo>:8443/login</param-value> ... 

The specific filter class mentioned above (CASFilter) is publicly available. This means that you can expand it by adding a custom adapter that will add your environment settings. This allows you to stay away from this nasty web.xml file.

0
source share

All Articles