wood burning stoves 2.0*
The moose likes Servlets and the fly likes still cant compile the code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

still cant compile the code

mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91

i get the following errors:
C:\epocketmoney_java>javac HTTPGetServlet.java
HTTPGetServlet.java:1: Package javax.servlet not found in import.
import javax.servlet.*;
^
HTTPGetServlet.java:2: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
^
error: File c:\javax\servlet\http\HttpServlet.class does not contain type HttpSe
rvlet as expected, but type javax.servlet.http.HttpServlet. Please remove the fi
le, or make sure it appears in the correct subdirectory of the class path.
HTTPGetServlet.java:5: Superclass HttpServlet of class HTTPGetServlet not found.
public class HTTPGetServlet extends HttpServlet

help!
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The first two look like servlet.jar is not in your classpath.

The last one is reminiscent of "trouble with packages". This type of error usually happens when a class file is found for an import, but in the incorrect package. It will find HTTPServlet, but it won't be where it expects to find it (ie: inside a folder structure that mirrors the package structure).

I got this error when I was compiling classes into the '.' directory that had package information, and then compiling classes that depended on those ones. It would find the class files, but they were in the wrong place, so it would give me: "Please remove the file, or make sure it appears in the correct subdirectory of the class path."

Which is a WAY more helpful message than the jdk1.3 would give you.

You're using 1.1.8 or 1.2 I think?
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
i am using java 1.2.2
the servlet is installed in c:\javax and directory structure is: c:\javax\servlet\http
my java is installed in c:\jdk1.2.2, with all the sub directories in it.
the only servlet.jar file i found is in my tomcat subdirectory: c:\program files\apache tomcat 4.0\common\lib\servlet.jar... i wonder if this is the correct file? the file size is 75 kb
i did delete a jar file in my jdk1.2.2 folder. it was a 16 mb file and it was called src.jar or something like that.... i read that this was just the source for java so i figured i didnt need it...
i wd like to have ur permission to email u directly to solve this problem....
regards
mansoor
my os is w/95
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Try something like this:

javac -classpath "c:\program files\apache tomcat 4.0\common\lib\servlet.jar" HTTPGetServlet.java

You would type that in at a prompt that is at the directory where the HTTPGetServlet.java file is.
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
Hey Mike!!!
it worked......
i wd not have figured this one ot for 10 years i am sure...it compiled!!!

odd tho....
any reason for the classpath not working in my autoexec.bat file??
ok

i have compiled it...
i tried to go a step further:
sine i have tomcat...and the when i click the Start tomcat it opens a java dos window and after a while gives me a "failed ..something something.." ....
i assume my tomcat is not running.
my frontpage is runningon port 80 and my fp sites work fine...
can i use fp server??
how can i fix my tomcat so it runs ...
thanks again!
mansoor
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

As for autoexec.bat, I'd need to see how you are setting it to diagnose the problem there.

If you start Tomcat, that window should remain open. If it's closing very quickly and you can't read the error, start a DOS window first and go to <tomcatHome>/bin/ and type startup. What is the error you get? You'll need to be more specific than "something something"

As for the fp server (FrontPage server?), if you are talking about PWS from Microsoft, this should not conflict with Tomcat, as it runs on port 80, and tomcat on port 8080. (So if you are testing if your Tomcat is running, you should be hitting http://localhost:8080/ )

Also, because you don't have Apache running on port 80, which can redirect to Tomcat when appropriate, you'll need to use Tomcat for your webserver as well... what this means is that whatever you are writing for Tomcat, you MUST specify :8080 after localhost.
[This message has been edited by Mike Curwen (edited October 22, 2001).]
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
Failed to load Main-Class manifest attribute from
Files\Apache
i get the above error when i start the apache server.....???
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

When you set your JAVA_HOME and TOMCAT_HOME in the autoexec.bat, don't use the long file name version. Use the SFN one (the one with ~'s)

So it would be something like:
set TOMCAT_HOME=c:\Progra~1\Apache~1\jakart~1

This might also be the reason your classpath is not being set properly in the autoexec.bat. Sometimes you can get away with surrounding LFN's with quotes, but I know for the startup script for Tomcat, there cannot be any spaces in the TOMCAT_HOME or JAVA_HOME.

I haven't seen that error before, but give that a try.
mansoor iqbal
Ranch Hand

Joined: Aug 14, 2000
Posts: 91
i have set up Catalina_home and java_home variable in my autoexec
i do use short files names ....
when i run the startup.bat form the directory, i get 'out of environment space' .... i reset my files=64 and buffers=64 in my config.sys but no diff.
i have a feeling this is the reason why tomcat is not running.
what do u think...
also....on the odd chance that it runs, how will i know that tomcat is runnning???
----------------
my autoexec.bat is:
path=c:\windows;c:\windows\command;c:\jdk1.2.2\bin;c:\tc\tcv3
C:\WINDOWS\COMMAND\MSCDEX /D:MSCD001 /V
doskey
cd\epocketmoney_java
set classpath=.;c:\javax\servlet;c:\jdk1.2.2\bin;c:\javax\servlet\http;
set JAVA_HOME=c:\jdk1.2.2\bin
set CATALINA_HOME=c:\Progra~1\Apache~1
-------------
so what do i do now??
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

That would definately be a reason Tomcat is not running.

Find the solution in the Tomcat documents: <tomcathome>\webapps\tomcat-docs\RUNNING.txt
scroll down to the (5) Troubleshooting section.

To test if Tomcat is running, just try to browse to http://localhost:8080/

One last thing about your CLASSPATH variable in autoexec.bat. I notice you have entries like: c:\javax\servlet and c:\javax\http\servlet. This is not really how to set the classpath. Replace classpath with a statement like this:
set CLASSPATH=.;<tomcathome>\common\lib\servlet.jar
When you are adding jar files to CLASSPATH for compiling source files, you need to *fully* specify the file, and not just the directory you'd find it in. If you do this, then you won't need to send it in to the javac command with -classpath switch, as I showed you previously.
[This message has been edited by Mike Curwen (edited October 24, 2001).]
Win Yu
Ranch Hand

Joined: Oct 17, 2001
Posts: 224
Hi there:
I put "d:\jakarta-tomcat-4.0\common\lib\servlet.jar" in my classpath, but it still does work. I used textpad and got :
D:\corejava\jservlet2-examples\ch02\Hello.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
D:\corejava\jservlet2-examples\ch02\Hello.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
D:\corejava\jservlet2-examples\ch02\Hello.java:5: cannot resolve symbol
symbol : class HttpServlet
location: class Hello
public class Hello extends HttpServlet {
^
D:\corejava\jservlet2-examples\ch02\Hello.java:7: cannot resolve symbol
symbol : class HttpServletRequest
location: class Hello
public void doGet(HttpServletRequest req, HttpServletResponse res)
^
D:\corejava\jservlet2-examples\ch02\Hello.java:7: cannot resolve symbol
symbol : class HttpServletResponse
location: class Hello
public void doGet(HttpServletRequest req, HttpServletResponse res)
^
D:\corejava\jservlet2-examples\ch02\Hello.java:8: cannot resolve symbol
symbol : class ServletException
location: class Hello
throws ServletException, IOException {
^
6 errors
Process completed with exit code 1
Can any one tell me Why. Thanks


Win
Jim Wang
Ranch Hand

Joined: Oct 04, 2001
Posts: 41
make one copy of your servlet.jar and put it under your jdk's lib folder.
Also you can put all the .jar files you may need during compiling into lib folder and .jar you may need for run time into jdk/../jre/ext.
you can try, it work for me.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If either mansoor or Win have further questions, please start a new (separate!) thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: still cant compile the code
 
Similar Threads
beginner question:error 404 servlet not available in Tomcat
Can Someone help me out?
NullPointerError In Servlet
Logic Help Please!!!
JSDK start and stop