Java – error: package javax.servlet.http does not exist

compiler-errorsjavaservletstomcat7

I am trying to create my first servlet and I am getting the error above when I try to compile my code. I have read on stackoverflow that this is due to SE JDK not containing the servlet api. However, I am compiling from the command line with the following:

javac -classpath C:/Tomcat7/lib/servlet-api.jar; 
      -d ../classes com/example/web/BeerSelect.java.

As you can see I am making reference to the servlet-api on the command line. Please can you advise why I am still getting this error. I am using tomcat 7

thanks


Solution

For anyone that is interested..I located my problem. It was problem with the Windows command shell and the fact that I had spaces in the directory names. I had the tomcat app saved as "tomcat 7" with a space. I was trying to reach it with "tomcat7" – that is no spaces.. The following line works

javac -classpath .;C:/Tomcat7/lib/servlet-api.jar;
      -d ../classes com/example/web/BeerSelect.java

Best Answer

If you are using Maven, you should add the servlet-api 2.5 dependency with the provided scope (see here for more details).

Related Topic