This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Classpath fun

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! That did the trick!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic