javaservletspathjavac

java servlet error on compile


So I was compiling a package using javac -Xlint from the command prompt and then it was complaining:

package javax.servlet does not exist

I know that this refers to the servlet jar from the tomcat and I acquired the jar...my question is how do I get javac to know the path to this jar so that it wont spill out this error


Solution

  • javac.exe has a -classpath option. Add all paths and JARs there.

    If you use an IDE, you'll need to figure out how to set up its build CLASSPATH.

    Or learn Ant.

    If you're developing a servlet, you'll have to deploy it in a WAR file. Fortunately the servlet.jar for Tomcat is in its /lib directory, so the Tomcat class loader will find it.

    Your WAR file's WEB-INF/lib JARs are automatically in the CLASSPATH at runtime; so are all the .class files Tomcat finds in your WEB-INF/classes.