8

I am getting this error when i start tomcat

java.lang.NoClassDefFoundError: javax/servlet/Filter
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClass0(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1301)
at    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:207)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:302)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:78)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3666)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4258)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)

i have already put the servlet.jar in classpath and tomcat_home/commons/lib folder

please can any one suggest what to do.

skaffman
  • 398,947
  • 96
  • 818
  • 769
prem
  • 163
  • 2
  • 3
  • 5

4 Answers4

11

java.lang.NoClassDefFoundError: javax/servlet/Filter

This particular exception can occur when you have got a copy of the servlet.jar which originated from an ancient Servlet 2.2 container or older and that file got precedence in classloading over Tomcat's own libraries. The Filter class was namely introduced in Servlet 2.3.


i have already put the servlet.jar in classpath and tomcat_home/commons/lib folder

You should not do that. Remove all servletcontainer-specific libraries from your /WEB-INF/lib, the "classpath" and the Tomcat's /common/lib folders.

The Tomcat servletcontainer already ships with the right APIs in its own /lib folder. You should not have any copy in your webapp's /WEB-INF/lib, nor elsewhere in the classpath, also not the ones from a completely different servletcontainer.

This common beginner's mistake of attempting to download/copy random servletcontainer specific libraries is commonly caused by the inability to compile servlet classes by javac or in the IDE. When using javac, you need to reference Tomcat's /lib in the -cp argument. When using an IDE, you need to reference Tomcat as Targeted runtime in project's properties.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • after removing the copy of servlet.jar and start the tomcat iam geting the error SEVERE: Exception starting filter springSecurityFilterChain java.lang.ClassNotFoundException: org.springframework.web.filter.DelegatingFilterProxy – prem Jan 14 '12 at 13:24
  • 1
    That's a different problem. Your initial problem is solved. You're now a step closer to a successful deploy. This exception just means that the given class (or, more concretely, the JAR containing the given class) is missing in the runtime classpath. You'd need to drop it in `/WEB-INF/lib`. Ask a new question if you stucks, this is completely unrelated to the current question. – BalusC Jan 14 '12 at 13:34
3

add this to your pom.xml, replace the version with any latest stable version. search for spring-web in mvnrepository.com and get the latest version

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.2.0.RELEASE</version>
</dependency>
agilob
  • 6,082
  • 3
  • 33
  • 49
Mohammed Rafeeq
  • 2,586
  • 25
  • 26
2

Unable to find the jar version of servlet jar that was causing issue, I explicitly added correct version of jar to Tomcat classpath :

enter image description here

This jar resides in %TOMCAT_HOME%/lib

Note : ensure servlet-api jar appears first.

blue-sky
  • 51,962
  • 152
  • 427
  • 752
0

It's because you have a servlet.jar somewhere that you shouldn't. Make sure the only servlet.jar you have is in commons/lib, per the FAQ.

Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
  • after removing the copy of servlet.jar and start the tomcat iam geting the error SEVERE: Exception starting filter springSecurityFilterChain java.lang.ClassNotFoundException: org.springframework.web.filter.DelegatingFilterProxy – prem Jan 14 '12 at 13:21