• 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 not found

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi--

I'm learning Java to do servlets and Tomcat. I've got Head First Java and Head First Serlvets.

I couldn't get a tutorial class (BeerSelect.java) to compile.

Here's the line:

import javax.serlvet.*;

First I made sure to point javac at Tomcat/Common/lib/servlet-api.jar...
that did not work.

So I downloaded Eclipse and got it running. I added the Tomcat classpath to the classpaths. Still did not work.

Then I noticed a couple things in Eclipse:

1) javax does not have a servlet package

2) if I'm using the servlet-api.jar as the classpath, I probably need another import statement, not the one I have (from the book).

so I tried this, because of the added classpath:

import servlet.*;

that didn't work either

how do I look inside the servlet-api.jar file to see what the correct path is?

what am I missing here?

Thanks

Matt
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have Tomcat running? If you do not java Java EE installed, Tomcat has to be running for servlets to compile
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt, welcome to JavaRanch!

javax.servlet is in Java EE (not SE). But if I'm not mistaken, it's also included as part of the Tomcat installation. I believe you want the following 3 items added to your CLASSPATH (where ... depends on where exactly these are installed on your system):

...Tomcat/common/lib/servlet-api.jar
...Tomcat/common/lib/jsp-api.jar
...Tomcat/webapps

I'm going to move this to the Tomcat forum where you will probably get better responses.
 
Matt Garland
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the quick responses

I have Java SE; Tomcat 5

running Tomcat did not have an effect

adding the other classpaths did not work...

I'm stumped.
 
Matt Garland
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
solved the problem

apparently eclipse comes with the servlet package

to make it active for your project, here's directions
(cut-and-pasted from http://www.devx.com/opensource/Article/20242/0/page/3, thanks Javid Jamae)

1. Click on the Libraries Tab (while still under Properties�>Java Build Path).
2. Click Add Variable.
3. Select ECLIPSE_HOME and click Extend.
4. Navigate to the plugins/org.eclipse.tomcat.4.1.x directory.
5. Select servlet.jar and click OK.
6. Click OK to exit the properties dialog.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rusty Shackleford:
Do you have Tomcat running? If you do not java Java EE installed, Tomcat has to be running for servlets to compile



Umm, no it doesn't.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure it does, at least when compiling on the command line. I haven't tried it using eclipse.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rusty Shackleford:
Sure it does, at least when compiling on the command line. I haven't tried it using eclipse.



I have to tell you, again, that as Bear says, whether Tomcat (or any other servlet container) is running or not has absolutely nothing to do with compiling servlets -- although if you'd like to explain to me how you think these things are related, I'd sit and listen because I'm interested in hearing about it. Maybe you're thinking about compiling JSPs?

The interfaces one needs to compile against are in common/lib/servlet-api.jar in the Tomcat distribution. As long as the compiler can see that file (i.e., it's on the class path) then you can compile servlets.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic