13

I am deploying a web application that is declared in web.xml and deployed as a .war file.

I am deploying on Jetty 9.1.x (but I think this question is not container specific).

My web.xml file is quite old and declares itself as a Servlet 2.4 application:

<web-app version="2.4" id="my_app"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
        http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

My configuration actually declares some Servlet 3.0 only features, like a default error page. These features do not validate according to the schema, but the features seem to work correctly.

Since I am using 3.0 features, I would like to change the declaration to be correct:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">

But I am scared to do this because I don't understand what the difference will be to Jetty.

Will changing the declaration have any effect on the runtime behavior of Jetty? Does Jetty treat a 2.4 app somehow differently than a 3.0 app?

Jen S.
  • 4,106
  • 4
  • 35
  • 44
  • 1
    I would think it does. For investigative purposes, add a `@WebListener` annotated class that implements `ServletContextListner` (or any other servlet listener type) to your class path with 3.0 and see if it's picked up. – Sotirios Delimanolis Jan 27 '14 at 14:45
  • My WebListener is not picked up regardless of the declaration. In all my testing, I could not find different behavior. What other feature could I test? – Jen S. Jan 27 '14 at 14:57
  • I think I see the problem: my app deploys gwt-servlet-2.5.1... so no matter what I do, my requests will be served through a 2.5 servlet and not a 3.0 servlet. – Jen S. Jan 27 '14 at 15:03
  • 1
    Yup, that's it. If you were on a Servlet 3.0 compatible container, I would think declaring a web-app version would make the container support only those features. I would try with a different container just to be sure. – Sotirios Delimanolis Jan 27 '14 at 15:04

1 Answers1

1

You should be able to simply swap the schema declaration from 2.4 to 3.0.

Scientific method

Initially I set off to prove it by doing diff between 2.4 and 2.5 and another one comparing 2.5 and 3.0.

I have convinced myself that the differences between 2.4 and 2.5 are only additive and the name space have shifted from j2ee to javaee.

However xsd schema for 3.0 is smaller then 1/3rd of the other two versions. Not sure how to proceed in this case (any ideas welcome!)


You can download all schemas from here and do the comparison yourself:


Not so scientific method

Here are the what's new articles describing each new version of the standard:

If you read in, the changes to web.xml descriptor mentioned in the articles are minute.

What I would do is simply list all the elements in your original web.xml and confirm that they do exist in this document describing the 3.0 schema.

Hope this helps!

diginoise
  • 7,352
  • 2
  • 31
  • 39