Reputation: 13
It's my first Servlet program but even after adding the classpath of servlet-api.jar
cmd gives me the same boring error saying: "java.servlet package does not exist"
Can anybody help me with this?
Upvotes: 0
Views: 2540
Reputation: 89209
First of all, Servlet is of javax.servlet
and not java.servlet
package. That might be your problem. Organize your servlet import in your code.
To run a servlet on Tomcat, you must place your WAR file (that contains the compiled Servlet) under TOMCAT_HOME/webapps
folder and run Tomcat from command line by calling startup
(which calls startup.bat file, and assuming you're in TOMCAT_HOME\bin
folder).
Upvotes: 0
Reputation: 1109715
Make sure that you've a concrete servletcontainer installed. For example, Apache Tomcat. At least the one where you target your webapplication to.
The Servlet API is then located in /path/to/Tomcat/lib/servlet-api.jar
file. You need to make sure that you include this path in the -cp
or -classpath
argument of the javac
command. Assuming that you're currently inside the root folder of all your Java code:
javac -cp .:/path/to/Tomcat/lib/servlet-api.jar com/example/SomeServlet.java
Or if it's on Windows, use semicolon ;
instead of colon :
as path separator and if the path contains spaces like so C:\Program Files\Tomcat\lib\servlet-api.jar
, then surround the invididual path with quotes:
javac -cp .;"C:\Program Files\Tomcat\lib\servlet-api.jar" com/example/SomeServlet.java
Upvotes: 1
Reputation: 1441
With dynamic web projects (eclipse) it should be automatically added. If not- just download the jar and add it to the class path.
Upvotes: 0
Reputation: 9511
Sounds like you're still not set up correctly. Double-check everything your classpath, print out the PATH in that particular CMD window and make sure that JAR is there. Sounds like you're not using Eclipse, so you'll have to do a lot of this confusing set-up work by hand.
Upvotes: 0