Archived

This topic is now archived and is closed to further replies.

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

This topic is 5889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites