score:-4

remove servlet.jar from source web-inf/lib folder as it is available in tomcat lib folder then it works fine

score:0

check inside the following directory for the jar file el-api.jar :c:\apache-tomcat-7.0.39\lib\el-api.jar if it exists then in this directory of your web application web-inf\lib\el-api.jar the jar should be removed

score:0

when your url pattern is wrong, this error may be occurred.

eg. if you wrote @webservlet("login"), this error will be shown. the correct one is @webservlet("/login").

score:0

exclusions and provided dependencies will not work in child projects.

if you are using inheritance in maven projects you must include this configuration on the parent pom.xml file. you will have a <parent>...</parent> section in your pom.xml if you are using inheritance. so you will have something like this in your parent pom.xml:

<groupid>some.groupid</groupid>
<version>1.0</version>
<artifactid>someartifactid</artifactid>
<packaging>pom</packaging>
<modules>
    <module>child-module-1</module>
    <module>child-module-2</module>
</modules>
<dependencies>
    <dependency>
        <groupid>javax.servlet</groupid>
        <artifactid>servlet-api</artifactid>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupid>javax.servlet.jsp</groupid>
        <artifactid>jsp-api</artifactid>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

score:0

the jax-ws dependency library “jaxws-rt.jar” is missing.

go here http://jax-ws.java.net/. download jax-ws ri distribution. unzip it and copy “jaxws-rt.jar” to tomcat library folder “{$tomcat}/lib“. restart tomcat.

score:0

typically when you see this message, it is benign. if it says

info: validatejarfile(/<webapp>/web-inf/lib/servlet-api-2.5.jar) - jar not loaded. 
see servlet spec 2.3, section 9.7.2. offending class: javax/servlet/servlet.class

it means it is ignoring your servlet-api-2.5.jar because tomcat already has a built-in version of that jar, so it isn't going to be using yours. typically this doesn't cause an issue.

if however it says web-inf/lib/my_jar.jar - jar not loaded...offending class: javax/servlet/servlet.class

then what you can do (in my instance, it's a shaded jar) is run

$ mvn dependency:tree

and discover that you have a transitive dependency on "something" that depends on a jar that is either servlet-api or something like it (ex: tomcat-servlet-api-9.0.0). so add an exclusion to that to your pom, ex: (in my case, tomcat, in your case, probably the ones mentioned in the other answers):

 <dependency>
    ...
    <exclusions>
      <exclusion>
        <groupid>org.apache.tomcat</groupid>
        <artifactid>tomcat-servlet</artifactid>
      </exclusion>
    </exclusions> 
</dependency>

score:0

from https://stackoverflow.com/a/9941668/778517

i did mvn dependency:tree and result was

(...)
[info] +- org.zkoss.zk:zkspring-core:jar:3.2.0:compile
[info] |  +- org.springframework:spring-beans:jar:3.0.7.release:compile
[info] |  +- org.springframework:spring-context:jar:3.0.7.release:compile
[info] |  |  \- org.springframework:spring-asm:jar:3.0.7.release:compile
[info] |  +- org.springframework:spring-web:jar:3.0.7.release:compile
[info] |  \- org.reflections:reflections:jar:0.9.5-rc2:compile
[info] |     +- com.google.collections:google-collections:jar:1.0:compile
[info] |     +- ch.qos.logback:logback-classic:jar:0.9.9:runtime
[info] |     |  \- ch.qos.logback:logback-core:jar:0.9.9:runtime
[info] |     +- com.google.code.gson:gson:jar:1.4:compile
[info] |     \- javax.servlet:servlet-api:jar:2.5:compile
(...)

so in pom.xml, zkspring-core i added the exclusions tag

(...)
             <groupid>org.zkoss.zk</groupid>
             <artifactid>zkspring-core</artifactid>
             <version>3.2.0</version>
+            <exclusions>
+                <exclusion>
+                <groupid>javax.servlet</groupid>
+                <artifactid>servlet-api</artifactid>
+                </exclusion>
+            </exclusions>
             </dependency>
(...)

after i ran mvn dependency:tree and javax.servlet:servlet-api:jar:2.5:compile is clean

(...)
[info] +- org.zkoss.zk:zkspring-core:jar:3.2.0:compile
[info] |  +- org.springframework:spring-beans:jar:3.0.7.release:compile
[info] |  +- org.springframework:spring-context:jar:3.0.7.release:compile
[info] |  |  \- org.springframework:spring-asm:jar:3.0.7.release:compile
[info] |  +- org.springframework:spring-web:jar:3.0.7.release:compile
[info] |  \- org.reflections:reflections:jar:0.9.5-rc2:compile
[info] |     +- com.google.collections:google-collections:jar:1.0:compile
[info] |     +- ch.qos.logback:logback-classic:jar:0.9.9:runtime
[info] |     |  \- ch.qos.logback:logback-core:jar:0.9.9:runtime
[info] |     \- com.google.code.gson:gson:jar:1.4:compile
(...)

score:1

i've been struggling with this issue and i've tried numerous "solutions".

however, in the end, the only one that worked and it actually took a few seconds to do it was to: delete and add back new server instance!

basically, i right clicked on my tomcat server in eclipse under servers and deleted it. next, i've added a new tomcat server. cleaned and redeployed the application and i got rid of this error.

score:2

you may find the following windows command line useful in tracking down the offending jar file. it creates an index of all the class files in all the jars in the folder. execute from within the lib folder of your deployed app, then search the index.txt file for the offending class.

for /r %x in (*.jar) do (echo %x & jar -tf %x) >> index.txt

score:2

maven dependency scope

provided : this is much like compile, but indicates you expect the jdk or a container to provide the dependency at runtime. for example, when building a web application for the java enterprise edition, you would set the dependency on the servlet api and related java ee apis to scope provided because the web container provides those classes. this scope is only available on the compilation and test classpath, and is not transitive.

score:4

to fix it, set the scope to provided. this tells maven use code servlet-api.jar for compiling and testing only, but not include it in the war file. the deployed container will “provide” the servlet-api.jar at runtime.

<dependency>
    <groupid>javax.servlet</groupid>
    <artifactid>servlet-api</artifactid>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

score:21

you get this warning message when the servlet api jar file has already been loaded in the container and you try to load it once again from lib directory.

the servlet specs say you are not allowed to have servlet.jar in your webapps lib directory.

  • get rid of the warning message by simply removing servlet.jar from your lib directory.
  • if you don't find the jar in the lib directory scan for your build path and remove the jar.

c:\program files\apache software foundation\tomcat 7.0\webapps\project\web-inf\lib

if you are running a maven project, change the javax.servlet-api dependency to scope provided in you pom.xml since the container already provided the servlet jar in itself.

score:114

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>

Related Query

More Query from same tag