• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I'am need help on page.no 82 HFS

 
manda prasad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

While I write the model class BeerExpert in the development directory com/example/model,and compile it,I get the error wrong name for the com/example/model/BeerExpert.java package.

Please clear my doubt : The specs of the model as described in the book on the same page,I understand that the model BeerExpert.java should be in development directory src/com/example/model ,then what does the directory structure means as referred in the second line of the specs.

The class BeerSelect.java in the development directory src/com/example/web does not recognise the model BeerExpert.java in the /model directory.Why??

Please help ,,advice what actually should I be doing with BeerExpert.java
 
ming wu
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
need your code to find out the problem. make sure you have a right package statement.
 
manda prasad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for responding :

Below class BeerSelect.java is in the development directory src/com/example/web


And this code below is class BeerExpert.java which is in development directory src/com/example/model


I'am able to compile just BeerSelect.java(without BeerExpert object code in it),but when I introduce BeerExpert code in it, I'am not able to compile it because it is not finding BeerExpert class definition.
Trying to compile BeerExpert alone I get compiler error as bad name for package.
Basically I need to know where should I place this BeerExpert.java so that it compiles and BeerSelect knows the location of the BeerExpert definition.
Hope this is clear

Thanx
 
ming wu
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to modify the CLASSPATH,
%CLASSPATH% should be "tomcathome\common\lib\servlet-api.jar;classes;." the dot ". " at the end is important
 
Jessica White
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe there is nothing wrong with your code.
However, you need to set your CLASSPATH to include
<whatever your dev directory>\classes
I suppose you put all your compiled class files under classes directory.
This path needs to be in CLASSPATH, then from this point on, your compiler can find your com.example.web or com.example.model package, otherwise, there is no way the compiler would know where to find your class files. Compiler would look into current directory, where you initiated javac command, but that's probably where your *.java files located, and the compiler can not find necessary class files.

Hope that helps.
 
manda prasad
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jessica and ming wu to reply..
I would like to know what is the correct command to be used for compiling
Please see below:

This is command prompt print

C:\kiran\MyProjects\beerV1>javac -classpath \Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;classes;. -d classes src\com\example\model\BeerExpert.java
javac: invalid flag: Files\Apache
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are u
sed
-classpath <path> Specify where to find user class files
-cp <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-endorseddirs <dirs> Override location of endorsed standards path
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release

-target <release> Generate class files for specific VM version
-version Version information
-help Print a synopsis of standard options
-X Print a synopsis of nonstandard options
-J<flag> Pass <flag> directly to the runtime system

And my Classpath is :
.;C:\kiran\MyProjects\beerV1\classes\;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;%CLASSPATH%

Thanks.
 
Jessica White
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set your CLASSPATH in control panel-->system, it should have:

.;C:\[your dev dir]\[project name]\classes;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\jsp-api.jar

Then when you compile, you are at:
C:\[your dev dir]\[project name]

do the following command

javac -d classes src\...\*.java

then you donot have to include CLASSPATH in your javac command.

When you run, do
cd classes

java com.*.MyApp (fully qualified package name must be used)

try this to see if it works
 
Monica negi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jessi, that helped
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic