Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

web-fragment.xml: I Don't Get It

DZone's Guide to

web-fragment.xml: I Don't Get It

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

I've been trying to understand web-fragment.xml, which is part of the Servlet 3.0 specification. The confusion comes from the discussion in this issue in NetBeans Issuezilla:

http://netbeans.org/bugzilla/show_bug.cgi?id=187548

There it is posited that a web-fragment.xml file makes sense "in a project in which a web framework or a support web library is being developed". Similarly, in Arun Gupta's introduction to web-fragment.xml in a Maven-Wicket application (here), he ends by saying: "It would be nice if the next version of wicket-*.jar can include “META-INF/web-fragment.xml” then everything will work out-of-the-box."

In other words, the idea appears to be that the provider of a web framework library (e.g., the provider of Wicket, the provider of Struts, the provider of JSF), will be providing a web-fragment.xml file inside the Wicket/Struts/JSF library.

However, let's take a look at the content of a web-fragment.xml file obtained from Arun's blog entry, below. Here you can see that the application class name is defined within the web-fragment.xml file:

 

However, isn't the application class name defined per application, rather than per web framework library? To use the web-fragment.xml file that Arun provided, I needed to change the package naming and class name of the Wicket application class in my own application. That can't be right.

I imagine that the web-fragment.xml file should, somehow, be defined per application. So, if NetBeans IDE only lets me create such a file within a Java SE library project, doesn't that mean that I should be defining my entire Wicket application within a Java SE project? Then one would be modularizing the web.xml file, with each fragment being provided by a different JAR, with each JAR contributing a framework-specific part of the application. But that, according to the NetBeans Issue above, is not the idea at all. 

Though I feel that the web-fragment.xml file should be defined within a web application, it appears that only JAR files packaged in WEB-INF/lib are scanned for META-INF/web-fragment.xml, i.e., WAR files are not searched for this file.

So either I don't get it or there's something odd going on. Probably I simply don't get it. Is there a real scenario anywhere where web-fragment.xml is demonstrated, i.e., where there is more than a single web-fragment.xml? (Though a real sample with even one single web-fragment.xml would be interesting to see.) Especially, where do web frameworks (e.g., Wicket, Struts, JSF) fit into the web-fragment world? (From this, it would appear that if I want to use a Wicket filter in a web-fragment.xml file, the whole Wicket application would be created in a JAR file, which means that Java SE Library projects in NetBeans IDE should let me add support for web frameworks to them.) I haven't found a relevant sample thus far.

 

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}