Im trying to create servlet for my project but encountered The import javax.servlet.annotation cannot be resolved
. I've already added javax.servlet
and servlet-api.jar
from tomcat. Please refer the image below.
-
2Oh please no, don't manually fiddle with container specific libraries. stackoverflow.com/questions/4076601/…– BalusCMar 20, 2012 at 5:31
4 Answers
By the screenshot it looks like you are importing servlet spec v2.5. The servlet annotations were added in servlet spec 3.0
http://docs.oracle.com/javaee/6/api/javax/servlet/annotation/package-summary.html
You will want to get the jar for a newer version then what you are currently using
Here is a chart showing the Tomcat version and the servlet spec it supports http://tomcat.apache.org/whichversion.html
-
2In other words, you need Tomcat 7.0 with a
web.xml
declared conform Servlet 3.0. Otherwise just live with<servlet>
stuff inweb.xml
. See also stackoverflow.com/tags/servlets/info– BalusCMar 20, 2012 at 5:32
Ensure You download the jar javax.servlet-api-3.0.1.jar from the link http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api/3.0.1
annotation is not in javax.servlet package. It is under java.lang.annotation.*
Please refer below link.. http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html
-
annotations are in more places then java.lang. The OP is not trying to create their own annotation– SeanMar 20, 2012 at 3:56
just import a package in the buildpath servlet-api.jar file with a version greater than 3.0