• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot compile servlet from commandline

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to compile my servlet class from the jdk bin directory and getting the following errors.i think my compiler is not recognizing the imports.Is there any problem with my classpath? (Scroll to see error trace)

javac -classpath C:/tomcat/common/lib/servlet-api.jar:classes:. -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstProject/src/com/example/web/BeerSelect.java


My servlet is at C:/Myprojects/FirstProject/src/com/example/web/BeerSelect.java
and my tomcat is at C:/tomcat/
and my current dir is :C:\Program Files\Java\jdk1.6.0_05\bin

Errors:
C:\Program Files\Java\jdk1.6.0_05\bin>javac -classpath C:/tomcat/common/lib/serv
let-api.jar:classes:. -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstP
roject/src/com/example/web/BeerSelect.java
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:1: package javax.
servlet does not exist
import javax.servlet.*;
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:2: package javax.
servlet.http does not exist
import javax.servlet.http.*;
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:5: cannot find sy
mbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class HttpServletRequest
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class HttpServletResponse
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class ServletException
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
 
kurt hanni
Ranch Hand
Posts: 140
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you running it on windows?

if yes, compile using this

javac -classpath "C:\tomcat\commons\lib\servlet-api.jar;classes" -d destFolder Sample.java
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as kurt suggested, Jars and directories must be separated by semi-colons under Windows.
 
J radolf
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the classpath for the SERVLETAPI.jar file properly.
 
Abdul Rahman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any luck amar ???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic