• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classpath fun  RSS feed

 
Bryan Douglas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am studying about servlets currently from the Headfirst book series, and I am stuck in chapter 3. I have to test some model logic, which is simply a plain old java class. I come from a C++ background, and while I have no problem designing and writing java code, I am quite lost on the art of building and compiling with Java.

I have one file, BeerExpert.java, which I have alread compiled. It's compiled .class file is located in C:\projects\beerV1\classes\com\example\model. I have another file, unitTest.java, which is located in C:\projects\beerV1\src\com\example\model, which is also where BeerExpert.java is located. In both java files, I put "package com.example.model;" at the top of the files. The source for the files is located at the bottom of this post.

When I try to compile unitTest.java, javac returns an error saying that the symbol BeerExpert cannot be found. When I compile, however, I am setting the classpath:
C:\projects\beerV1\src\com\example\model>javac -cp C:\projects\beerV1\classes\com\example\model unitTest.java

Where I am making the mistake? In the source files? Do I have to call javac from a specific directory due to the pacakge naming?


unitTest.java





BeerExpert.java
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

cd c:\projects\beerV1\classes
javac -cp c:\projects\beerV1\classes com\example\model\unitTest.java

The classpath should reference the root of the package directory tree. In this case the classes directory.
[ September 20, 2006: Message edited by: Scott Johnson ]
 
Bryan Douglas
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! That did the trick!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!