jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

dreambigcoder picture dreambigcoder · Mar 24, 2013 · Viewed 176k times · Source

I am running a Maven project which is also a dynamic web project. I have used all Spring libraries in Maven. I created web.xml, but when I start my Tomcat 7 server I am getting the following message:

INFO: validateJarFile(C:\Users\mibvzd0\workspace\.metadata\.plugins\
org.eclipse.wst.server.core\tmp2\wtpwebapps\hapi_hl7\WEB-INF\lib\
servlet-api-2.4.jar) - jar not loaded.
See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

I tried deleting the servlet from webapp/lib, but it didn't work. Let me know what should be done in my case.

Answer

JB Nizet picture JB Nizet · Mar 24, 2013

The servlet API .jar file must not be embedded inside the webapp since, obviously, the container already has these classes in its classpath: it implements the interfaces contained in this jar.

The dependency should be in the provided scope, rather than the default compile scope, in your Maven pom:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>