I have the jre7 and jdk1.7.0 installed along with the Tomcat 7.0 but it shows this error. servlet.http is not the only one that "does not exist", there are also other (servlet.) components.
Can anybody help me with this?
UPDATE: This error occurs when I try the follow command: javac -classpath servlet-api.jar WebTest.java
If you're using the command console to compile the servlet, then you should include Tomcat's /lib/servlet-api. jar in the compile classpath. If you're using an IDE, then you should integrate Tomcat in the IDE and reference it as target runtime in the project.
The javax. servlet. http package contains a number of classes and interfaces that describe and define the contracts between a servlet class running under the HTTP protocol and the runtime environment provided for an instance of such a class by a conforming servlet container.
It contains, among others, the files /usr/share/java/servlet-api-2.5. jar and /usr/share/java/jsp-api-2.1. jar , which are the servlet and JSP libraries you need.
Right-click your project, click on properties->Java Build path->Libraries tab->click Add External JARs->Browse for servlet-api. jar and select it->click OK to update the build path. Right-click the project, click properties->Java Build Path->click ADD JARs->find servlet-api.
If you are working with maven project, then add following dependency to your pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
If you're using the command console to compile the servlet, then you should include Tomcat's /lib/servlet-api.jar
in the compile classpath.
javac -cp .:/path/to/tomcat/lib/servlet-api.jar com/example/MyServlet.java
(use ;
instead of :
as path separator in Windows)
If you're using an IDE, then you should integrate Tomcat in the IDE and reference it as target runtime in the project. If you're using Eclipse as IDE, see also this for more detail: How do I import the javax.servlet API in my Eclipse project?
Your CLASSPATH variable does not point to the directory containing the javax classes. The CLASSPATH variable specifies where the java compiler should look for java class file resources. If it does not know to look in the javax directory, then it will never find the file(s) you are after.
On *nix, try:
javac -cp $CLASSPATH:$CATALINA_HOME/lib/servlet-api.jar Filename.java
Or on Windows, try:
javac -cp %CLASSPATH%;%CATALINA_HOME%\lib\servlet-api.jar Filename.java
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