Karadous Karadous - 1 year ago 276
Java Question

Compile error: package javax.servlet does not exist

I have a package in which I import javax.servlet.* and javax.servlet.http.*
When I try to compile it in command prompt I get the error

package javax.servlet does not exist

I use JDK 1.7.0 and Tomcat 6.0.

Answer Source

You need to add the path to Tomcat 6's /lib/servlet-api.jar file to the compile time classpath.

javac -cp .;/path/to/Tomcat/lib/servlet-api.jar com/example/MyServletClass.java

The classpath is where Java needs to look for imported dependencies. It will otherwise default to the current folder which is included as . in the above example. The ; is the path separator for Windows; if you're using an Unix based OS, then you need to use : instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download