Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class with package / directory tree

 
Pin Ting
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pin Ting
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dirk.
Now I got a very clear picture .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic