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

Head First Servlet : Beer Version 2 Problem

Asad Salim
Greenhorn

Joined: May 31, 2011
Posts: 13
Hello Guys,

I don't where I'm going wrong in this problem. Below are details:

Below is my BeerExpert.java file which is stored at src/com/example/model



When I compile this file , it gets compile successfully
C:\Beer-V2>javac -d src\com\example\model BeerExpert.java

and create the .class file correctly in the directory classes/com/example/model

But ,when I try to compile BeerSelect.java (Which is at src\com\example\web), which is as below


It tells me that it can't find the package com.example.model as below

C:\MyProject\Beer-V2>javac -classpath "c:\Tomcat 6.0\lib\servlet-api.jar" -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors

C:\MyProject\Beer-V2>

Thanks in advance
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
This is a classpath issue. Make sure your development directory is in your classpath. i.e the directory above com/example/model


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Asad Salim
Greenhorn

Joined: May 31, 2011
Posts: 13
Classpath issue , I m sorry , but i m not able to understand the issue . Since , I m running it from my Development environment folder itself i.e. Beer-v2

Below is my Development Directory structure

c:\>MyProject\Beer-V2> (I m executing the above command from here)

Under Beer-V2 , I have the below folders
src
(BeerExpert.java is located at src\com\example\model)
(BeerSelect.java is located at src\com\example\web)

classes
(BeerExpert.java is located at classes\com\example\model)
BeerSelect.java is not created , as the compilation fails at the below instance

C:\MyProject\Beer-V2>javac -classpath "c:\Tomcat 6.0\lib\servlet-api.jar" -d cla
sses src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors
Asad Salim
Greenhorn

Joined: May 31, 2011
Posts: 13
Thanks Bosun Bello , I could figure the problem and could resolve it.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
No problem. You can post back exactly what you did, so that others that run into similar issues can see it.
Asad Salim
Greenhorn

Joined: May 31, 2011
Posts: 13

C:\MyProject\Beer-V2>javac -classpath "c:\Tomcat 6.0\lib\servlet-api.jar";"c:\MyProject\Beer-V2\src" -d classes src\com\example\web\BeerSelect.java

Solved the issue.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38508
    
  23
Check whether the code in the book and the code from the website it identical. There may be package names added to the website version.
salil patil
Greenhorn

Joined: Jun 16, 2013
Posts: 1

(BeerExpert.java is located at classes\com\example\model)
BeerSelect.java is not created , as the compilation fails at the below instance

C:\MyProject\Beer-V2>javac -classpath "c:\Tomcat 6.0\lib\servlet-api.jar" -d cla
sses src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
src\com\example\web\BeerSelect.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be=new BeerExpert();
^
3 errors

why can't my environment variable do this work without below line ....


C:\MyProject\Beer-V2>javac -classpath "c:\Tomcat 6.0\lib\servlet-api.jar";"c:\MyProject\Beer-V2\src" -d classes src\com\example\web\BeerSelect.java
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Head First Servlet : Beer Version 2 Problem