I was just reading an overview of Java EE 6 and I was struck by their handling of the web.xml file. In this article it is trumpeted as a great new feature, the monolithic web.xml file can now be chopped up into a set of files so you can group setup and configuration. And god knows, if thereâs something you get a lot of in Java, itâs configuration.
Anyway, the heart of this is good, itâs in a good place. Thereâs no longer one big file, we can have several files and each one has its own purpose. You might even get a web.xml file that comes with some third party framework youâre using like Struts. However, then it starts to go off the rails (no pun intended):
However, because Servlet 3.0 enables you to modularize your deployment descriptors, the order in which these descriptors are processed can be important. For example, the order in which the descriptors for an application are processed affects the order in which servlets, listeners, and filters are invoked. With Servlet 3.0, you can specify the order in which deployment descriptors are processed.
Servlet 3.0 supports absolute ordering and relative ordering of deployment descriptors. Your specify absolute ordering using the
<absolute-ordering>
element in theweb.xml
file. You specify relative ordering with an<ordering>
element in theweb-fragment.xml
file.
Uh huh. When Rails (as in Ruby on Rails) needed to order a bunch of stuff like migrations, they made a simple convention (for example, 001_filename.rb, 002_filename.rb, 003_filename.rb). When that convention didnât work out for large groups of developers they changed and went with the date and time instead (as in, 0080402122512_one.rb). Rails pretty much always picks a convention whenever possible and then if they need to they come up with a way to override it.
Thereâs nothing wrong with having <ordering> and <absolute-ordering> elements at all. Give the developer an override, fine, but give them an easy way to just name their stuff and order it automatically without that. What the heck is wrong with files named 001_web.xml and 200_web.xml? Seriously? Why can there never ever be a convention that the software reacts to and uses so you donât have to hack up some configuration file 100% of the time?