I am facing this exception on tomcat server startup.
Here I am using javax.servlet-api-4.0.1.jar
in my project, and I included this for runtime also.
But when I deploy my application into tomcat 8.5, tomcat picks the older jar servlet-api
from its /lib folder.
I know this method setSessionTimeout
is included in servlet 4.0, but how will I direct tomcat to pick jar from my project's WEB-INF/lib folder instead of tomcat/lib.
I tried to place servlet-api-4.0 jar into tomcat/lib and deleting older jar, then project starts properly. But is it the correct way? Can't tomcat pick the latest jar from my project's lib directory.
Please help.
CodePudding user response:
Do not bring your own servlet API jar.
You claim you're using Tomcat 8.5, which implements servlet spec 3.1. Bringing along a newer jar will not magically make it implement this newer spec.
If you want 4.0, use Tomcat 9. And don't bring your own servlet API. The version that ships with Tomcat is perfectly fine. Depending on the way you build, you need some version of it at build time, but you do not package it for runtime use (e.g. Maven calls it "provided", in gradle I see "compile" or "compileOnly")