• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Head First Servlet : Beer Version 2 Problem

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a classpath issue. Make sure your development directory is in your classpath. i.e the directory above com/example/model
 
Asad Salim
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bosun Bello , I could figure the problem and could resolve it.
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problem. You can post back exactly what you did, so that others that run into similar issues can see it.
 
Asad Salim
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic