aspose file tools*
The moose likes Tomcat and the fly likes javax.servlet not found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "javax.servlet not found" Watch "javax.servlet not found" New topic
Author

javax.servlet not found

Matt Garland
Greenhorn

Joined: Feb 24, 2006
Posts: 8
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
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Do you have Tomcat running? If you do not java Java EE installed, Tomcat has to be running for servlets to compile


"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Matt Garland
Greenhorn

Joined: Feb 24, 2006
Posts: 8
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

Joined: Feb 24, 2006
Posts: 8
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61592
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Sure it does, at least when compiling on the command line. I haven't tried it using eclipse.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.servlet not found