Reputation: 1232
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?
Upvotes: 1
Views: 11551
Reputation: 11
you are gettig this error because servlet-api.jar file is not present in your path which you have written . Try to download servlet-api.jar file from this link http://www.java2s.com/Code/Jar/s/Downloadservletapijar.htm and extract the zip file in the download folder and then move servlet-api.jar to /var/lib/tomcat8/lib/ folder .
And for complie java file first go to "src" folder in your project by terminal and write command..
sudo javac -d ../classes/ *.java -cp /var/lib/tomcat8/lib/servlet-api.jar
Upvotes: -1
Reputation: 2079
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.
Upvotes: 2