File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet does not exist

 
B Crosthwaite
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,

I am a beginner with java and new with this forum so be patient with me

I am using Mac OS X version 10.5.5 and i have installed Tomcat version 6.0.18
I have set up:
CATALINA_HOME /Library/Tomcat/Home
JAVA_HOME /Library/Tomcat/Home
CLASSPATH /Library/Java/Home/lib/servlet-api.jar;/Library/Java/Home/lib/jsp-api.jar

When i start tomcat i can bring up the tomcat home page (http://localhost:8080) with no problem. But when i try to compile a servlet through my terminal i get the "javax.servlet does not exist" and "javax.servlet.http does not exist" errors.

I have read on the internet and this forum that it is my CLASSPATH that is the culprit but i am unsure what my error is.

If anyone can help me i would greatly appreciate it

Thanks in advance.

-Ben
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add servlet-api.jar from the Tomcat distribution to the classpath of the compilation.

JAVA_HOME /Library/Tomcat/Home
CLASSPATH /Library/Java/Home/lib/servlet-api.jar;/Library/Java/Home/lib/jsp-api.jar


Your setting for JAVA_HOME is wrong. It's not the Tomcat root.

And did you copy servlet-api.jar and jsp-api.jar to /Library/Java/Home? If so, that's a poor idea. You should just reference them in-place in the Tomcat distribution. That way you are sure that the jar you are compiling against is the same as the one you are running against.
[ October 22, 2008: Message edited by: Bear Bibeault ]
 
B Crosthwaite
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for your quick reply. Please could you be a little bit more specific, maybe provide an example.

Thanks for your patience.

-Ben
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this is about learning how to properly set up the classpath for a compile (you might want to include more details as to how you are doing that), I'm moving this to a more appropriate forum.
 
B Crosthwaite
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to compile my servlet. In my terminal i direct to the correct location (using cd), then when i am at the correct location i use the javac command.

For Example: javac HelloWorld.java

i think this is what you mean.

-Ben
 
B Crosthwaite
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Bear,

I have just noticed that you edited your first post.

I followed this to install mt Tomcat:
http://www.malisphoto.com/tips/tomcatonosx.html

and Tomcat worked exactly how it said it would.

How should i be setting up my JAVA_HOME?

-Ben
 
roomy iqbal
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I have got exactly same problem and its been 2 days I am trying to sort it out but it doesnt seem to work. I dont know what is classpath variable.. is it the same as PATH variable in environment variables? I have already set it to point to ....\tomcat 6.0\lib\servlet-api.jar
but its still not working is there anything i m missing or that i dont know. Please let me know I would really appreciate your help
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
roomy,

If you are using an IDE like Eclipse or NetBeans you can just right click on the project and configure your class path by adding the appropriate libraries.

If you are still using cmd and notepad, open your cmd and type java(assuming your java.exe is in the system path). It gives you a lot many options and 2 of them are for adding libraries to your classpath. (-cp and -classpath)

And NO Path and classpath are not same.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go back to the servlets forum, and go through all the FAQ there. You will probably find something for your problem there.
 
roomy iqbal
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry but I have tried this cmd

javac -jc C:\program files\apache software foundation\tomcat 6.0\lib\servlet-api.jar ShoppingServlet.java

this one didnt work so i searched on internet and i have created a new variable CLASSPATH in environment variables and added this path there but it still doesnt work... i will check the FAQs now but if you have any other sugession please leme know.
 
Vijitha Kumara
Bartender
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so i searched on internet and i have created a new variable CLASSPATH in environment variables and added this path there but it still doesnt work


How did you tried it? Fired up a new command prompt? Because It's necessary for changes to take effect.
By the way what command did you use there? javac nameofthefile.java ?
[ October 23, 2008: Message edited by: Vijitha Kumara ]
 
B Crosthwaite
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roomy,

Did you sort out this problem?

-Ben
 
Campbell Ritchie
Sheriff
Pie
Posts: 47222
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't add anything to your CLASSPATH environment variables; add them at the command-line. You will probably find details of the java and javac tools here, and you can find the classpath options from their webpages.
 
roomy iqbal
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have restarted the cmd prompt i have even restarted my computer here is what i get when i type command

C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ebookshop\WEB-INF
\src\ebookshop>javac -cp c:\Program Files\Apache Software Foundation\Tomcat 6.0\
lib\servlet-api.jar ShoppingServlet.java
javac: invalid flag: Files\Apache
Usage: javac <options> <source files>
use -help for a list of possible options


OK GUYS THANKS VERY MUCH I HAVE MANAGED TO FIX IT I JUST HAD TO PUT IT IN QUOTES


[ October 23, 2008: Message edited by: roomy iqbal ]
[ October 23, 2008: Message edited by: roomy iqbal ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic