• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just installed J2EE, got the app server, etc, however, I can't compile my "Hello World" servlet!

Help
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would u pls post the error msg that u got when u tried to compile ur HelloWorld Servlet ?

ram.
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
install the J2EE SDK, and include j2ee.jar which is contained therein in the classpath when compiling.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Definitely a classpath issue. This page might help.
 
Marcus Laubli
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jeroen. I'm hoping to get this thing to compile sometime later today.. working on something else right now.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need j2ee.jar somewhere in your CLASSPATH -- specifically -- just ..\..\lib won't work.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Margaret Moser
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic