?
Solved

CLASSPATH and packages

Posted on 1998-06-09
5
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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