Solved

CLASSPATH and packages

Posted on 1998-06-09
5
231 Views
Last Modified: 2013-11-23
Im about going out of my skull here..
First off im using the JDK1.1.5 on a WIN95 system (single user)
I have been working with Java for a while now however I have never created my own packages or really even had to set the CLASSPATH.  I've only imported the API packages up til now.
Now I've wanted to experiement with creating my own packages and using packages that I have received from other people (I found one that was written by Jim Buzbee called houseblend that allows you to rotate and manupulate fonts, etc...its at www.nyx.net/~jbuzbee/font.html (for a plug))
anyway using this as an example of my problem...
the package is called houseblend
I have set up my CLASSPATH as the following:
set CLASSPATH=c:\jdk115\;c:\jdk115\myjava\classes
and have tried putting the package houseblend in a directory off both of these directories the class file that is my concern is called HersheyFont.class
so the path to that file is c:\jdk115\houseblend\HersheyFont.class
The HersheyFont.java file compiles without a hitch
but when I try to compile the test.java class that came with the package it gives me the following error which leads me to believe that I have somehow specified the CLASSPATH or the directory structure wrong:
test.java:19: Package houseblend not found in import
OR
if i have the period "." at the front of my classpath the compiler would give me this error:
error: File.\HersheyFont.class does not contain type HersheyFont as expected but type houseblend.HersheyFont.
Please remove the file or make sure that it appears in the correct subdirectory of the class path

Obviously something is messed up with my classpath or subdirectories (very few errors are THAT specific but I still cant seem to figure it out)
The test.java has multiple import statements one of which is:  import houseblend.*;
and there is a package statement in the HersheyFont class

Any comments or questions would be greatly appreciated
I'll assign it as easy for now (it sure SEEMS easy... the documentation I have read about creating packages is straightforward)
I think Im in the forest so deep that i cant see the trees

Mark


0
Comment
Question by:mbunkows
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1222773
Where is test.java class located and what package does it belong to?
0
 

Author Comment

by:mbunkows
ID: 1222774
test.java is located in the same directory as the package itself
so in the example situation it is located in the c:\jdk115\myjava\classes\houseblend directory.. it is not part of any package itself... it was just included to test the actual
font package (and it imports the package)

If I remove the package statement from the source code (and the import) and run the test class it works (because its in the same directory)

but id really like to know what im missing here

0
 
LVL 5

Accepted Solution

by:
msmolyak earned 50 total points
ID: 1222775
Classes which belong to different packages should not really live in the same directory. If the class belongs to a package, then its directory is pretty much defined (relative to CLASSPATH directory). I am not exactly sure where you should put the class not belonging to any package which imports other packages.  Try either putting test.java into some package (houseblend or your own) or try moving it out of houseblend directory (e.g. one level up).
0
 

Author Comment

by:mbunkows
ID: 1222776
your quick ... let me try this out
be back in 5-10 minutes :)


0
 

Author Comment

by:mbunkows
ID: 1222777
Amazing!
I guess it makes since from a organizational point of view
the funny thing is if i would have tried it the way i was actually going to use it, it would have worked.

Thanks alot for the help (and helping me out of the forest)
Mark
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now