Help! Three web.xml Deployment Descriptors!

In Plant Cactus in NetBeans IDE 4.1, I explained how to use Cactus to test servlets deployed to Tomcat. In the second step of the procedure, I showed entries that need to be specified in the web.xml file for the Cactus servlets ServletRedirector and ServletTestRunner.

However, in which web.xml file should you put those entries? When I wrote that blog entry, my assumption was that the only web.xml file worth considering is the one that is part of your web application. I was wrong. As Petr Pisl pointed out to me in an e-mail, there are two other web.xml files, each of which could conceivably include servlet mappings. So, as a reminder to myself, and possibly as a help to others, here is a quick run-down of the web.xml files that you have available to you, followed by an explanation of the impact of the location of the web.xml file:

  • ${project.dir}/web/WEB-INF/web.xml. Only used by the project in ${project.dir}.

  • ${netbeans.user.dir}/jakarta-tomcat-5.5.7_base/conf/web.xml. Used by all projects that use ${netbeans.user.dir}; usually, this means all projects on the local machine.

  • ${netbeans.install.dir}/enterprise1/jakarta-tomcat-5.5.7/conf/web.xml. Used by all projects that use NetBeans IDE installed in ${netbeans.install.dir}; possibly, this means everyone sharing the installation at ${netbeans.install.dir}.

As you can see, the order in which the web.xml files are listed above reflects the impact which each of them has. The web.xml file in your project affects only that project, while in ${netbeans.user.dir} it affects all projects on your machine. Only if you want to share deployment settings with other users would you change the web.xml file in the ${netbeans.install.dir}, if the machine in question is being shared with other users.

While using Cactus, though, I'll be changing a single project's web.xml file much less, because most changes I make to web.xml file for Cactus are useful for other projects too. Therefore, I'll be changing the web.xml file in my ${netbeans.user.dir}, from now onwards. (Plus, when you move your application from a development server to a production server, you'd need to remove Cactus servlets from your project's web.xml file, if they are there. This also applies to the use of the HTTP Monitor for servers that are not bundled with the IDE -- so I used the wrong web.xml file in this blog entry.) On the other hand, since my machine isn't shared with other users, I might as well use the web.xml file in my ${netbeans.install.dir} -- this way, the changes to the web.xml file are not lost when I delete my user directory...


Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014