Cannot Compile Servlet
I'm having trouble compiling my servlet, because it says the servlet classes can't be found.
CreateAccount.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
I googled a bunch and most people with this problem had their CLASSPATH set incorrectly. Here is the result when I echo my classpath:
> echo $CLASSPATH .:/usr/local/java/bin:/usr/local/tomcat/apache-tomcat-6.0.18/lib/servlet-api.jar
I copy and paste the path to servlet-api.jar listed in it, /usr/local/tomcat/apache-tomcat-6.0.18/lib/, and I browse to that directory and sure enough the jar file is there.
> ls
annotations-api.jar catalina-ha.jar catalina-tribes.jar jasper-el.jar jasper-jdt.jar servlet-api.jar tomcat-dbcp.jar tomcat-i18n-fr.jar
catalina-ant.jar catalina.jar el-api.jar jasper.jar jsp-api.jar tomcat-coyote.jar tomcat-i18n-es.jar tomcat-i18n-ja.jar
So I'm not sure why it's telling the classes can't be found, since it should be pointing to them. What am I forgetting here?
mps727
Junior Poster in Training
68 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0
What are you using to compile?
If you are using an IDE, then you need to add that jar as a library in the project properties.
Edit: As that is the CLASSPATH for an IDE. The System CLASSPATH is good for almost nothing, anymore. Do the following concerning classpaths
1. When running from the command line without the "-jar" option use the -classpath option.
2. When running from the command line with the "-jar" option, you must configure the classpath in the manifest file properly.
3. When running/compiling from an IDE, you must configure the librarires in that IDE's project properties.
4. When running from a web container / application server you must place the jars in the proper locaions (see the manula for the web server / application container in question).
IDE's and web containers / application servers ignore the system classpath. When using the -jar option, both the System CLASSPATH and the -classpath options are ignored and only the manifest file's classpath is used. The only time that the system CLASSPATH is still used, is when running or compiling from the command line with neither the -jar nor the -classpath options.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
mps727
Junior Poster in Training
68 posts since Nov 2006
Reputation Points: 10
Solved Threads: 0