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.
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.
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>
Unable to find the jar version of servlet jar that was causing issue, I explicitly added correct version of jar to Tomcat classpath :
This jar resides in %TOMCAT_HOME%/lib
Note : ensure servlet-api jar appears first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With