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 javax.servlet does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javax.servlet does not exist" Watch "javax.servlet does not exist" New topic
Author

javax.servlet does not exist

B Crosthwaite
Ranch Hand

Joined: Oct 22, 2008
Posts: 39
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

Joined: Jan 10, 2002
Posts: 61298
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
B Crosthwaite
Ranch Hand

Joined: Oct 22, 2008
Posts: 39
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

Joined: Jan 10, 2002
Posts: 61298
    
  66

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

Joined: Oct 22, 2008
Posts: 39
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

Joined: Oct 22, 2008
Posts: 39
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

Joined: Oct 23, 2008
Posts: 7
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

Joined: Dec 16, 2007
Posts: 151
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.


Cheers!
RSR
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
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

Joined: Oct 23, 2008
Posts: 7
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

Joined: Mar 24, 2008
Posts: 3833

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 ]

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
B Crosthwaite
Ranch Hand

Joined: Oct 22, 2008
Posts: 39
Hi Roomy,

Did you sort out this problem?

-Ben
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
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

Joined: Oct 23, 2008
Posts: 7
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 ]
 
GeeCON Prague 2014
 
subject: javax.servlet does not exist