aspose file tools*
The moose likes Tomcat and the fly likes Error importing class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Error importing class" Watch "Error importing class" New topic
Author

Error importing class

shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Hello all, I am having trouble compiling a java class that includes the imports javax.servlet.* and javax.servlet.http.*. The error I get says the directory cannot be accessed. I'm not sure what the problem is, but might it have something to do with my classpath? I'm not sure so if anyone has any ideas, they would be well appreciated. Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Sounds like a setup issue. What servlet container are you using?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Well I'm using the JSDK version 4 and the Tomcat server.
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Sorry I meant version 1.4
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

OK, I'm going to move this along to the Tomcat forum where you can get some help on properly setting up Tomcat.
Alex Leung
Greenhorn

Joined: Dec 08, 2003
Posts: 26
I had similar problems when I start using servlets, but not sure if your is the same.
Do correct me if I am wrong, I thought SDK 1.4 do not include servlet packages. For me, to use servlets I downloaded a seperate file 'servlet-2_2' from Sun and put it in the lib directory inside where I installed the SDK. then set path including the lib directory as well, then my servlets compile. Try to test if your servlets packages exist first by writing a simple (empty) class like:
----------------------
import javax.servlet.*;
public class A {}
---------------------
hope this helps.
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
I think you may be right because I tried the simple class like you suggested Alex and it would not compile. So I have to download a separate 'servlet 2-2' file from sun? I'll try that thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Tomcat contains a jar file with all servlet related classes - you should use the version in your installed Tomcat to avoid version conflicts. The name is either servlet.jar or servlet-api.jar and is in \common\lib
Bill
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Thanks for telling me that William, but even when I have specified the path to the servlet.jar file in the common/lib folder of Tomcat, I still get the same error. Am I right in thinking that it is the CLASSPATH that needs to be set to this destination?
Alex Leung
Greenhorn

Joined: Dec 08, 2003
Posts: 26
First, this might sound a little amusing, but are you sure your normal java files compiles? I mean the ones not using servlet packages. If you can compile normal java files, and you have the servlet jar file ready, then it can only mean two things (to me), either:
- you have set up the path to the servlet jar file incorrectly.
- or your servlet code is incorrect.
hope this helps.
shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
Well I can tell yu that my 'normal' java classes do compile ok and I've tried including many different paths in the classpath to try and get the imports working but they don't. My classpath basically has the jakarta tomcat servlet.jar path in it and also the servlet specification I downloaded from sun separately. However I have noticed that people have said they have included '.jar' files or 'src' files that found in their jsdk download. When I donwloaded the servlet spec, the files I got were in a javax/servlet/http..etc folder. Was I supposed to put this in the lib folder of my sdk? I'm so confused!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Sometimes people forget that in CLASSPATH you must include the name of the jar file. The JVM won't automatically include all jars in a directory.
Several years ago I gave up fooling with CLASSPATH as an environment variable and went entirely to ANT controlled compilation.
Here is how I specify the classpath in ANT for a current project - really all on one line in the ANT build.xml:

The joy of ANT is that once set up, compiling that project always has the right classpath and the environment variable is ignored. Yes, there is a learning curve, but you will be glad you did.
Bill
Alex Leung
Greenhorn

Joined: Dec 08, 2003
Posts: 26
Ok, try this: do not use classpath for the moment, I can tell you I did not have to use classpath variable to get my java code working. I only use path, try to change all the directories you set for classpath to path instead.
hope this helps.
 
wood burning stoves
 
subject: Error importing class