• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to compile servlet with model class reference

 
amarkirt saroay
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • 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
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic