File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Exercise from HF Servlets & JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exercise from HF Servlets & JSP" Watch "Exercise from HF Servlets & JSP" New topic
Author

Exercise from HF Servlets & JSP

Dave Moir
Greenhorn

Joined: Jun 12, 2005
Posts: 3
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sirish Kumar Gongal Reddy
Ranch Hand

Joined: Oct 25, 2004
Posts: 109
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

Joined: Jun 12, 2005
Posts: 3
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

Joined: Jun 12, 2005
Posts: 3
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

Joined: Dec 11, 2004
Posts: 13410

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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Exercise from HF Servlets & JSP
 
Similar Threads
help for HFSJ - CH 3 Page 84
Trouble compiling servlet HFSJ pg 85
can't compile a servlet
HF Servlet and Java - MVC tutorial
Compiling servlet version two code in HFSJ