aspose file tools*
The moose likes Beginning Java and the fly likes javax.Servlet.. Oh where, oh wher can it be? 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.. Oh where, oh wher can it be?" Watch "javax.Servlet.. Oh where, oh wher can it be?" New topic
Author

javax.Servlet.. Oh where, oh wher can it be?

Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I just installed J2EE, got the app server, etc, however, I can't compile my "Hello World" servlet!

Help


Marcus L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Would u pls post the error msg that u got when u tried to compile ur HelloWorld Servlet ?

ram.
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
HelloWorldServlet.java:2: package javax.servlet.http does not exist
import javax.servlet.*;
^
HelloWorldServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^

And it only gets worse from there!
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
install the J2EE SDK, and include j2ee.jar which is contained therein in the classpath when compiling.


42
Hemang Thanki
Greenhorn

Joined: Jan 24, 2005
Posts: 18
Add this entry in your classpath environment variable (e.g. for me it is c:\Sun\AppServer\lib). It searches for the j2ee.jar file path when compile.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Definitely a classpath issue. This page might help.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Is rt.jar included inside j2ee.jar? I scanned and found that I had 11 versions of rt.jar ranging from 11 to 37 MB.

Seeing that the J2EE things are still at version 1.4, what should I do here? Will my 1.5 version of rt.jar be ok with the older version of j2ee.jar?

What should I do?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
you DO NOT add rt.jar to your classpath. It's for internal use by the virtual machine only to run your applications.

The version number of J2EE has NO relation to the version number of the JDK/J2SDK.
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Thank you Jeroen. I'm hoping to get this thing to compile sometime later today.. working on something else right now.
Margaret Moser
Greenhorn

Joined: Mar 03, 2005
Posts: 5
I am running into the same problem, trying to set up the simple MVC app from the Head First JSP book. I get the same pile of compilation errors about "package javax.servlet does not exist" etc.

Here's my compile command (just like the book):
c:\dev\projects\beerV1>javac -classpath c:\tomcat\common\lib\servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java

Here's my CLASSPATH environmental variable:
.;C:\tomcat\common\lib;C:\dev\jdk142_03\lib;C:\Sun\AppServer\lib

Here's my PATH:
C:\Sun\AppServer\bin;C:\dev\jdk142_03\bin;C:\dev\jdk142_03\lib;C:\tomcat\common\lib;C:\tomcat\bin

I've spent a few hours throwing different things into my env. variables, changing compiler flags, etc., but no dice.

Can anyone help, please?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
You need j2ee.jar somewhere in your CLASSPATH -- specifically -- just ..\..\lib won't work.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
if you're using tomcat, you should add <tomcat install directory>/common/lib/servlet-api.jar to your classpath when you're trying to compile servlets. Just to be safe, I usually include every jar file in that directory in my class path while compiling J2EE programs.

Note to java beginners: It is not enough to include a directory containing jar files in your classpath. You must name each jar file individually. That's why having C:\tomcat\common\lib in your classpath didn't help.
[ March 03, 2005: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Margaret Moser
Greenhorn

Joined: Mar 03, 2005
Posts: 5
Success! Thank you Marilyn and Merrill - I worship you both.

Follow-up question: doesn't including all the individual jar files lead to seriously bloated env. variables? or is there a way to toss them all in there concisely (like including ../lib/*.jar)? I had the impression that Windows wouldn't deal with wildcards in variables, but I wouldn't mind being wrong...
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Usually you don't need all the jar files, but you must name each one that you actually do need. No wildcards in the classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.Servlet.. Oh where, oh wher can it be?