Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Unable to compile servlet with model class reference

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to compile my servlet after ading the model class as described in HFJ chapter 3,Below is my servlet and followed by error i am getting in compilation.
Please let me know if and how I need to change my classpath?
I have copied my model class file(BeerExpert.class) and placed it under the corresponding folder in Web-inf classes,still the compiler is not getting the package com.example.model ?

Servlet code:


Command:
C:\Program Files\Java\jdk1.6.0_05\bin>javac -classpath "C:/tomcat/common/lib/servlet-api.jar;classes;." -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstProject/src/com/example/web/SelectBeer.java



Errors:


C:\Myprojects\FirstProject\src\com\example\web\SelectBeer.java:3: package com.eample.model does not exist
import com.example.model.*;
^
C:\Myprojects\FirstProject\src\com\example\web\SelectBeer.java:22: cannot find
ymbol
symbol : class BeerExpert
location: class com.example.web.SelectBeer
BeerExpert be=new BeerExpert();
^
C:\Myprojects\FirstProject\src\com\example\web\SelectBeer.java:22: cannot find
ymbol
symbol : class BeerExpert
location: class com.example.web.SelectBeer
BeerExpert be=new BeerExpert();
^
3 errors

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

C:\Program Files\Java\jdk1.6.0_05\bin>javac -classpath "C:/tomcat/common/lib/servlet-api.jar;classes;." -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstProject/src/com/example/web/SelectBeer.java



classpath miss out the folder to reach the package name of your model class, change to this and try , it is because your model class is in the C:/Myprojects/FirstProject/classes provided you have compiled your model class correctly according to the HFSJ book

C:\Program Files\Java\jdk1.6.0_05\bin>javac -classpath "C:/tomcat/common/lib/servlet-api.jar;C:/Myprojects/FirstProject/classes;classes;." -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstProject/src/com/example/web/SelectBeer.java
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic