This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Exercise from HF Servlets & JSP

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to this but need to learn fast for a project at work. I am going throught the HF Servlets & JSP book and am doing the Beer tutorial. I am working in Windows 2K as this is the OS at work.
The problem is that the BeerSelect servlet will not compile as it cannot find the BeerExpert class with the import statement. Everything is set up exactly as shown in the book.
I have found in the earlier exercises that I have to change the compile commands slightly from those shown in the book (I believe the examples are screenshots from Mac OS X)to work in Windows. Here is the command and output:

C:\MyProjects\beerV1>javac -classpath C:\tomcat\common\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:3: package classes.com.example.model does not exist
import classes.com.example.model.*;
^
src\com\example\web\BeerSelect.java:20: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src\com\example\web\BeerSelect.java:20: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

javac -classpath C:\tomcat\common\lib\servlet-api.jar



The only thing on your classpath is servlet-api.jar.
If other classes are needed you will need to add them to your classpath.

If you aren't familiar with setting up classpaths, it would be worth your while to break away from servlets and follow a Java tutorial or two.
The "First Cup Of Java" tutorial on http://java.sun.com is excellent.

Most servlet books assume some familiarity with Java and don't go into a lot of detail abou this sort of thing.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
i request you one thing if you don't mind plz send me the meterial "First Cup of Java".i went through sun's site but i was failed to download.i'm looking forward for that meterial sir.
Thanking you..
Thanks&Regards,
G Sirish Reddy.,
sirish_msc@yahoo.com.
 
Dave Moir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought about it and figured it out. This worked:

C:\MyProjects\beerV1>javac -classpath C:\tomcat\common\lib\servlet-api.jar;classes -d classes src\com\example\web\BeerSelect.java

Thanks for your help.
 
Dave Moir
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In reply to G Siresh Reddy's request for the address of the tutorial, here it is:

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Dave Moir:
I thought about it and figured it out. This worked:

C:\MyProjects\beerV1>javac -classpath C:\tomcat\common\lib\servlet-api.jar;classes -d classes src\com\example\web\BeerSelect.java

Thanks for your help.



If you have a small number of dependencies this technique is fine.
As the number grows, however, it can become a bit cumbersome.
The easiest way to handle this is to set your CLASSPATH environment variable and let the compiler find the libraries that way.

Glad you've got it working.
[ June 12, 2005: Message edited by: Ben Souther ]
 
All of the following truths are shameless lies. But what about this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!