• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.servlet not found

 
Matt Garland
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic