File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes need basic help to compile first servelet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need basic help to compile first servelet" Watch "need basic help to compile first servelet" New topic
Author

need basic help to compile first servelet

neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
Hello,
I have installed jakarta-tomcat-5.5.9 on Windows XP OS.
I am following HFSJ for reference.While comiling the simple servlet as mentioned in chapter-3, i am getting loads of compilation errors as.......

I have checked that servlet-jar file is present in proper path (c:/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar)

C:\Documents and Settings\neetika\Desktop\MyProject\beerV1>javac -classpath c:/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java src/com/example/web/BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost( HttpServletRequest request, HttpServletResponse resp
onse) throws IOException, ServletException {
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
public void doPost( HttpServletRequest request, HttpServletResponse resp
onse) throws IOException, ServletException {
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
public void doPost( HttpServletRequest request, HttpServletResponse resp
onse) throws IOException, ServletException {

^
6 errors


How to compile this
Please help.
Big Thnx in advance
neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
If I set the classpath from cmd prompt as......

C:\Documents and Settings\neetika\Desktop\MyProject\beerV1>set CLASSPATH=.;C:\jakarta-tomcat-5.5.9\common\lib\servlet-api.jar

and then simply giving

C:\Documents and Settings\neetika\Desktop\MyProject\beerV1>javac src/com/example/web/BeerSelect.java

then it is compiling.Can Anybody explain me this unexpected behaviour.Y is this not working with -classpath option during compilation.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You'll probably get better help with classpath and javac questions in the Java In General (Beginner) forum so.... moving.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
On Windows the separator used in the CLASSPATH is ; not :


Joanne
neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
Originally posted by Joanne Neal:
On Windows the separator used in the CLASSPATH is ; not :


I did not get , how this is related to my query. Do you want to say that whatever compilation errors I am getting is because of colon used??? But this is same as given in HFSJ. Kindly clarify
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
With your classpath as it is, the compiler is looking for a file or directory called
c:/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar:classes:.
i.e. it thinks that it is a single file name because there are no separators

If you change it to
c:/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar;classes;.
then the compiler will look for a file called c:/jakarta-tomcat-5.5.9/common/lib/servlet-api.jar and will look for classes in the 'classes' directory and the current directory.

The example in the HSFJ was probably written for use on Unix where the separator is a :
[ June 09, 2006: Message edited by: Joanne Neal ]
neetika sharma
Ranch Hand

Joined: May 19, 2006
Posts: 89
Thanks Joanne...I am able to compile it sucessfully without any doubts :-)..thnx a lot for clarifying
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need basic help to compile first servelet