| Author |
class with package / directory tree
|
Pin Ting
Greenhorn
Joined: May 28, 2003
Posts: 22
|
|
Dear all ranchers, Let's say test.class belongs to package domain1.domain2. (That is, the first line of test.java is "package domain1.domain2;") Now I would like to execute test.class. Is it necessary to place test.class in the folder "[any_other_folder]\domain1\domain2" and then execute "java domain1.domain2.test" under [any_other_folder]? Is there a way to execute the class without building the directory tree corresponding to the class' package hierarchy? Thanks.
|
Never do things the hard way if you don't have a good reason.
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Is there a way to execute the class without building the directory tree corresponding to the class' package hierarchy? No. Note that the directory structure and class file could be packaged in a JAR file, which is then included in the CLASSPATH setting. Is it necessary to place test.class in the folder "[any_other_folder]\domain1\domain2" and then execute "java domain1.domain2.test" under [any_other_folder]? Not exactly. As previously mentioned, the class file and directory structures could be in a JAR file. All that is necessary, is that the base of the directory structure is somehow included in the CLASSPATH setting, then the class can be used from anywhere.
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
So far as I know your directory structure must match your package structure when using Sun compiler & JVM, and probably most others. Visual Age breaks the rules by keeping all source and classes in a repository instead of a file structure, but they have their own JVM and I'm guesing that's how they break the rules.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Pin Ting
Greenhorn
Joined: May 28, 2003
Posts: 22
|
|
Thanks, Dirk. Now I got a very clear picture .
|
 |
 |
|
|
subject: class with package / directory tree
|
|
|