Tomcat – Package javax.servlet.*; does not exist, other javax package also not exist

packageservletstomcat

I use JDK7,JRE7 and Tomcat 7. I already mentioned the classpath of Tomcat library in command prompt. But when compiling the servlet I got an error:

package javax.servlet does not exist

Please help. Thanks in advance.

Best Answer

I tested your example and the compiler error was shown when you have mispelling in the path.

Command:

javac -classpath "D:\tomcatX\lib\servlet-api.jar;classes;" -d classes src\Ch1Servlet.java

Error:

src\Ch1Servlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;

Command:

javac -classpath "D:\tomcat\lib\servlet-api.jar;classes;" -d classes src\Ch1Servlet.java

Now it is ok.

So check carefully your path to the Tomcat (I think than it is lack of some spaces):

javac -classpath "C:\ProgramFiles\ApacheSoftwareFoundation\Tomcat7.0\lib\servlet-api.jar;classes;‌​" -d classes src\Ch1Servlet.java

Probably it should be:

javac -classpath "C:\Program Files\Apache Software Foundation\Tomcat7.0\lib\servlet-api.jar;classes;‌​" -d classes src\Ch1Servlet.java
Related Topic