Java web app - What determines my Servlet API version? Does it get specified in web.xml?

stackoverflow picture stackoverflow · Aug 27, 2012 · Viewed 28.2k times · Source

I'm using Eclipse EE Juno and my current web application is using Dynamic web modules 2.4. I'm trying to bump the version up to 3.0 but for some reason I'm unable to. when I try to change the version in project facets I get Cannot change version of project facet Dynamic Web Module to 3.0. Is it possible that there some bunk line in my web.xml file that determines this? How do I change the Dynamic web modules version if not from Eclipse project facet setting alone?

Answer

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Aug 27, 2012

Servlet 2.4 in web.xml:

<web-app version="2.4"
  xmlns="http://java.sun.com/xml/ns/j2ee"
  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">

Servlet 3.0 in web.xml:

<web-app version="3.0"
  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">

That's the only difference. The rest is your IDE configuration. In order to use Servlet 3.0 you must have 3.0 JARs on the CLASSPATH so that new annotations and other classes are available. But do not include servlet JAR in your WAR, the implementation should come from the servlet container.