Java packages question

blackrose

Limp Gawd
Joined
Sep 3, 2004
Messages
339
So my program (asteroids clone, for the hell of it) is starting to get a little big to just keep all the files in one directory/package. I'm trying to break it up into packages, and for now I'm only making one extra package. So, I have the root package named asteroids, and another subpackage asteroids.command (for all of my commands like new game, save, quit, etc.). Now I don't know if packages support this or not, but each command object implements a command interface, and also needs references to objects in the asteroids package. I'm compiling from the command line in the root asteroids directory, and each command object in the asteroids.command package says it can't find the symbols (classes) in the asteroids package. Does package organization work this way (classes in subpackage importing from higher up in the hierarchy), or am I just missing some compiler options? Thanks for any help.

PS When I'm compiling this is the command: C:\asteroids> javac -d . .\command\*.java
 
Yeah, you can do that with packages without any troubles. The compiler needs to be told where all of your classes live. You need to specify the classpath setting using -cp.

You might try the following:

javac -cp . -d . .\command\*.java
 
Back
Top