wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Packages" Watch "Packages" New topic
Author

Packages

Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi,
I have a resonable knowledge of actually programming Java, but I cannot grasp how to get packages working. I understand how to declare that something is part of a package in the code, and that the package hierarchy is produced using directory structure on the hard-drive - but I have no idea where to put this directory structure, and how to make my Java programmes find the package!? E.g if I store a package in d:\MyPackages\PackageOne, how does the compiler find it?
thanks,
Ben


SCJP 1.4, www.gsi3d.org.uk
Peter Phung
Ranch Hand

Joined: Dec 06, 2001
Posts: 138
you should compile the files in the package from the directory where the package is stored. To compile Packages on my (linux)pc i would use
peter@linux:~ >javac MyPackages/PackageOne/Class1.java
where "peter@linux:~ >" is the prompt. I also run my applications from the same prompt. I'm not totally sure that windows follows the same rules but it should be similar.
HTH


Pete<br />"Reality is an illusion <br />brought on by a lack of <br />drink, drugs and smut"
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Hello,
It looks like you want to learn a bit about the options available when using javac:
javac - Java programming language compiler
and
Setting the class path
Good Luck.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...and a short tutorial on using packages
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by Ben Wood:
but I have no idea where to put this directory structure,

Anywhere you'd like that you can tell the compiler and the JRE (JVM) to find the files.
and how to make my Java programmes find the package!?

with your import statement(s)
E.g if I store a package in d:\MyPackages\PackageOne, how does the compiler find it?

You'll usually let the compiler know the location of relevant packages and classes with the import statements in the class definition. In one of the above links you'll also find information on setting the classpath for the compiler.
The JRE (JVM) will need to also be able to find the necessary classes and packages, in which case you might need to set the classpath accordingly. Some information on doing this is referenced above, and a quick search on this forum is sure to turn up more information. (Note: the search page link is at the top right of this page.)
Good Luck.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Packages
 
Similar Threads
compiling interdependent classes and packages
Compile with -cp or -classpath
Please heeelp..Can't get "packages" to work
package vs directory
compiling interdependent classes and pachages