File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exercise from HF Servlets & JSP

 
Dave Moir
Greenhorn
Posts: 3
  • 0
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • 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.
 
Sirish Kumar Gongal Reddy
Ranch Hand
Posts: 109
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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 Redhat VI Editor
  • 0
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic