echo $CLASSPATH
/home/user/tomcat/lib/server-api.jar
echo $JAVA_HOME
.:/usr/lib/jvm/java-6-sun
but when I try to compile .java which are in class folder
javac *.java
I get
HelloServlet.java:2: package javax.servlet does not exist
and additional 5 similar errors.
I get no errors when
javac -cp /home/user/tomcat/lib/servlet-api.jar *.java
Why is that? What should I change to make it work without -cp /path?
Looks like your classpath doesn’t actually contain servlet-api.jar. The echo of CLASSPATH shows that it has server-api.jar in the path, but not servlet-api.jar. Try adding servlet-api.jar to your CLASSPATH definition and see if it works then.