wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Problem in making Beer Expert app from Head First Servlet Book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in making Beer Expert app from Head First Servlet Book" Watch "Problem in making Beer Expert app from Head First Servlet Book" New topic
Author

Problem in making Beer Expert app from Head First Servlet Book

Shadab Alam
Greenhorn

Joined: Mar 07, 2010
Posts: 3
Hii friends I m new to the Servlet world. I am going through the Head First Servlet book and facing difficulty in Chapter 3 while making the Beer Expert web app.

I need to compile the model class -




When I compile the above class on Windows the command prompt says -

"Note: src\com\example\model\BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

However the class is compiled. After that the book says me to compile Servlet version 2 -




When I compile the Servlet Vertion two the command prompt gives three errors-

src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:13: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:13: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors


Please help me out
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3023
    
  35

Howdy, Shadab,
Welcome to JavaRanch

Please UseCodeTags when you post a code. It's unnecessarily hard to read the code otherwise. Please edit your post to add code tags by clicking the button.

This problem is just about packaging and importing - it has nothing to do with servlets. Can you show us the way which you used to compile these classes?


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Charles 'King
Ranch Hand

Joined: Jul 05, 2009
Posts: 56

The compiler can't find your classes or package you're attempting to import. Are you using an IDE or compiling from the command line? If the latter, post your command.
Shadab Alam
Greenhorn

Joined: Mar 07, 2010
Posts: 3
Thanks for reply. Sorry I joined JavaRanch today, so I was not aware of the rules.

My model class is in "D:\MyProjects\beerV1\src\com\example\model" directory
and the Servlet is in "D:\MyProjects\beerV1\src\com\example\web" directory.
My current working directory on Windows command prompt is "D:\MyProjects\beerV1".

To compile the model class I typed on the command prompt
javac -d classes src\com\example\model\BeerExpert.java

The class is compiled but I got the warnings that I mentioned in the first post.

Now to compile the servlet, from the current working directory, i.e "D:\MyProjects\beerV1" I type the following on the command prompt
javac -classpath C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;classes:. -d classes src\com\example\web\BeerSelect.java

And I got the errors that I wrote in my first post. Please help
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
Shadab Alam wrote:Now to compile the servlet, from the current working directory, i.e "D:\MyProjects\beerV1" I type the following on the command prompt
javac -classpath C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar;classes:. -d classes src\com\example\web\BeerSelect.java

And I got the errors that I wrote in my first post. Please help


Have a look at your classpath entry for your servlet compilation. You must realize that command-line parameters are separated by spaces.
You need to enclose that classpath value in double quotes. Also, what is the second value? It looks like classes:.
That is, "classes" then a colon, then a period. Perhaps you meant to use a semicolon?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Moved to beginning Java as this has less to do with servlets than with learning how to compile Java classes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Vermette
Greenhorn

Joined: Mar 08, 2010
Posts: 1
Shadab says:
When I compile the above class on Windows the command prompt says -

"Note: src\com\example\model\BeerExpert.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

However the class is compiled.


Shadab - Later versions of Java will generate that error because, unlike previous versions, the Collection
classes now work with generics, and can enforce the object type that they contain. Your program builds
a List of Strings. Replace the line that creates the brands list with the following, and your warnings should
go away:



What this does is to declare that your new List will only accept String objects. A compile-time error
will be thrown if you try to put any other type of object in the list.

--Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in making Beer Expert app from Head First Servlet Book
 
Similar Threads
Head First Servlet : Beer Version 2 Problem
weird problem
can't compile a servlet
can't import own model
Problem in making Beer Expert app from Head First Servlet Book