[java] Importing my own class... (How to?)

Started by
2 comments, last by Xorcist 22 years, 5 months ago
Okay I've got a class, it's compiled, now I need to import it... how the hell do I do that! If the class resides in the same directory as my class containing main I have no problem, but as soon as I relocated my class to a different directory I can't seem to get it to import. Is there a way to pass import a fully declared path? I know java.lang.whatever actually resolves to %ClassPath%\java\lang\whatever, and I've tried putting my own directory below %ClassPath% but that still doesn't work! Help! {Can someone maybe show me a code example?} Edited by - Xorcist on November 2, 2001 7:23:29 PM
Advertisement
Ah, the joys of the path. You probably just have to set the classpath, either at the command prompt if it''s just temporary or in your autoexec.bat if it''s more permanent. Just try this:

java -classpath /mydir MyClass
Um... someone told me I need to use the package keyword to declare my class with a valid path (even if it is only a single class) and then it would work if I placed it in the proper sub-directory off of %ClassPath%. Can anyone explain why I need this? Does import only work on packages? And if so why does my class automatically import when in it''s the same directory (not having used a package statement)? Is it just me or is Java one hell of a confusing language...
Check this out.

Its an article explainning in detail the packaging structure in Java.

This topic is closed to new replies.

Advertisement