• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error importing class

 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a setup issue. What servlet container are you using?
 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'm using the JSDK version 4 and the Tomcat server.
 
shuzo monsoon
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I meant version 1.4
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic