Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

trouble importing javax.servlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just got Head First Servlets & JSPs, but am stuck at the first real exercise. Specifically I can't seem to import the javax.servlet, javax.servletHTTP packages. I set the classpath to Library/tomcat/common/lib/servlets-api.jar and try to compile but it isn't finding the servlet packages for some reason.

I'm using the terminal to compile and have tried setting the classpath to everything(and in every way) I can think of. I see the package in my tomcat folder, I just can't seem to access it.

Any ideas would be greatly appreciated.

Thanks
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are indeed including the correct jar to pick up the javax.servlet and javax.servlet.http packages.

How exactly are you adding the jar file to your compile classpath? That's the most likely point of failure.
 
Wyatt Humphries
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Among the things I've tried are;

1.) setting the classpath at compile time with
javac -classpath /Library/tomcat/common/lib/servlet-api.jar -d classes src/Ch1Servlet.java (taken straight out of the book)

2.) setting the classpath as a shell variable with
export CLASSPATH=/Library/tomcat/common/lib/servlet-api.jar

I also tried copying the jar file to where I think my Java Home directory is.

So far no luck. I understand classpath but have never really had to worry too much about setting it. Up until now everything I've done at home has been with the standard jdk and never had to set the classpath. And at work I use WSAD and never have to worry about setting it. Now I've got the Head First book and want to spend some time learning more about Servlets and JSPs at home on my iMac, but so far I've been stuck on this problem for a couple days now. I've searched the internet and tried everthing I've found, I've searched different forums (this is the only mac specific) with no luck. I do know something about Java (am a SCJP) and a little about J2ee, but right now this is making me feel like an idiot, because I can't figure it out!
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is indeed incredibly odd. I just tried compiling a basic servlet from the command line (been years since I've done that) on my iBook with no problems at all.

My test servlet was



I created a base folder j, and put TestServlet.java in j/xyz.

I set the working directory to j, and compiled using


javac -classpath /Library/Tomcat/common/lib/servlet-api.jar xyz/TestServlet.java



No issues.

There's gotta be something basic you're missing.

P.S. I said that I haven't compiled at the command line for years. Once you figure out what the issue is, I highly recommned adopting Ant for your build needs. You'll never look back.
 
Wyatt Humphries
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input Bear. I agree it's got to be something simple I'm missing. I've read a little about Ant and will learn it as I go along, for now I wanted to start at the beginning (of the book) and go step by step, thus why I'm compiling from command line.

When I get home this afternoon I'm going to start over and see if I can get it to work. I'll post here any progress or break throughs I have.

Thanks

Edit: It did indeed to be something obvious that I was missing. All along I though my classpath was starting at my user and looking in my Library/tomcat/... When it was actually starting at my hard drive, which makes sense but since when I log into the termial I am automatically starting in my users folder I just assumed that's where my classpath was starting to look. Dumb Mistake. The funny thing is I have tomcat installed in both Library's (unnecessarily) which led to all the confusion. The one in my root Library folder just didn't have the servlet-api.jar it had the servlet.jar. Anyway thanks for the help Bear at least you re-affirmed my own thought that I was missing something simple, leading me find my error.
[ March 18, 2005: Message edited by: Wyatt Humphries ]
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!