0

My application currently uses servlet-api.jar version 2.4 for compilation.
The jar gets packaged with the code and is deployed on the tomcat server.
The Web.xml also has the same version

<web-app id="WebApp_ID" 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">

But now the tomcat where we have deployed the code is upgrading to servlet-api.jar version 3.0.

And we are required to stop bundling the jar with our code and instead use the tomcat provided jar.

I would like to know :

1) Can I keep the web.xml intact (i.e. no mention of 3.0) and only change the pom.xml to compile the code using 3.0? Will there be any impact on the application functioning?


[Reference 1] java, tomcat: what is the meaning of the id attribute in the tag web-app in web.xml?
[Reference 2] http://docs.oracle.com/cd/E13222_01/wls/docs100/webapp/web_xml.html
[Reference 3] Java web app - What determines my Servlet API version? Does it get specified in web.xml?

Community
  • 1
  • 1
Jeril Nadar
  • 175
  • 3
  • 10

1 Answers1

1

The Servlet specification is backward compatible, so a 2.4 web app should run in a 3.0 container, and you may continue to compile your app against the Servlet 2.4 API and leave web.xml unchanged while deploying to a 3.0 container.

You should never package a servlet API jar in your WAR. At runtime, the application will always use the API and implementation provided by the container.

Regarding the Tomcat upgrade, I suppose what you meant to say is your installation was upgraded from Tomcat 5.x(?) (based on Servlet 2.4) to Tomcat 7.x (based on Servlet 3.0).

Simply upgrading the servlet API jar in an older Tomcat installation is not a good idea...

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63
  • You are right. We are not going to bundle the jar with the code. It will be provided by the container. And yes, it is Tomcat 7.0 – Jeril Nadar Jul 23 '14 at 05:46