Solved

CLASSPATH and packages

Posted on 1998-06-09
5
232 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is JNDI datasource in spring 1 50
unix in java example 9 53
Java DateChooser? 3 29
reverse digits of a number using for loop 5 36
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.

920 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

13 Experts available now in Live!

Get 1:1 Help Now