user1706538
user1706538

Reputation: 641

eclipse servlet java.lang.ClassNotFoundException: javax.servlet.Servlet

I keep getting this error: java.lang.ClassNotFoundException: javax.servlet.Servlet when I attempt to run my servlet in eclipse.

I am using the web version of eclipse in conjunction with Tomcat. I have servlet-api.jar in the library, as well as javaee-6.0.jar imported (though I believe I am using java 7, this was the most recent version of this I could find)

enter image description here

So why do I keep getting this error? I've scoured the web and the solution has always been servlet-api.jar, but I have this file in the library to no benefit.

Thank you in advance!

Upvotes: 0

Views: 6796

Answers (3)

grepit
grepit

Reputation: 22382

You correctly have added servlet.jar and javaee.jar. The error you specified is typically happens when one of those two files are missing. However, since you have those files, I recommend doing the following:

  • Removed the jar files and add them back in to your project enter image description here
  • Once you added them back in then do a clean build enter image description here
  • If none of the above steps fixes your problem then try creating a new web application and add all of your jar files again.

Upvotes: 0

Sajith Silva
Sajith Silva

Reputation: 823

Even though you have your servlet-api.jar you most probably dont need to bundle it with your war. Generally tomcat uses it own servlet-api, which is located ./common/lib/servlet-api.jar.

Most probably you are missing this, which causes the ClassNotFoundException

Upvotes: 1

Simo
Simo

Reputation: 2414

Is that error happing during the compilation or during the run?

Did you configure Eclipse to point to the Tomcat server? In order to run a web server in eclipse using tomcat, you need to tell eclipse about tomcat first. Here is where you ca find the instruction. http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

Upvotes: 1

Related Questions