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 my first servlet not Compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "my first servlet not Compiling" Watch "my first servlet not Compiling" New topic
Author

my first servlet not Compiling

abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130



note : i have installed j2eesdk-1_4_02_2005Q2-windows and also tomcat 6.0


out put is

D:\>javac Welcomserv.java
Welcomserv.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
Welcomserv.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Welcomserv.java:4: cannot resolve symbol
symbol : class HttpServlet
location: class Welcomserv
public class Welcomserv extends HttpServlet
^
Welcomserv.java:6: cannot resolve symbol
symbol : class HttpSerletRequest
location: class Welcomserv
public void doGet(HttpSerletRequest req, HttpServletResponse res) throws IOExcep
tion
^
Welcomserv.java:6: cannot resolve symbol
symbol : class HttpServletResponse
location: class Welcomserv
public void doGet(HttpSerletRequest req, HttpServletResponse res) throws IOExcep
tion
^
5 errors


Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

You have to set the classpath to refer servlet-api implementation in order to compile the servlet. (e.g.: javac -cp <Tomcat6Home>/lib/servlet-api.jar <source files>)

Note that you don't need both J2EE SDK (probably the IDE if you are referring to that here may required) and Tomcat to do this...


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Aniket S. Kulkarni
Ranch Hand

Joined: Jun 15, 2011
Posts: 87

@abhay:Vijitha is correct.
Include try,catch block or write ServletException in throws clause .


Aniket Kulkarni
Oracle Certified Professional, Java SE 6 Programmer.
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
i have tried all these methods already .. but still facing same errors
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

abhay jain wrote:i have tried all these methods already .. but still facing same errors

Can you show us the command you tried to compile and the errors you get now?
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
sorry i have closed that window .. but i have compiled it successfully .. actually i tried (as you suggested) a new way and it was as follows

:
i created a batch file to compile every java program [path was : D:\Sun\AppServer\lib\j2ee.jar ]
then i put both java and that batch file in a directory


THANKS A LOT MY FRIEND
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
i am sure there some thing that i am missing but what is that ???

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
\servlet-api.jar" Welcomserv.java



Welcomserv.java:4: cannot access javax.servlet.http.HttpServlet
bad class file: D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servl
et-api.jar(javax/servlet/http/HttpServlet.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
public class Welcomserv extends HttpServlet
^
1 error
Anupam Dee
Ranch Hand

Joined: Oct 18, 2010
Posts: 42

Try using this

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib" Welcomserv.java
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
Anupam Dee wrote:Try using this

D:\>javac -classpath "D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib" Welcomserv.java


not working ................5 errors (same as above)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Is the servlets package in Java™ EE?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my first servlet not Compiling