Java Reference
In-Depth Information
jdk1.4
bin
jre
Contains compiler,
interpreter, tools,
etc.
Contains rt.jar archive
containing the standard
packages
bin
classes
lib
If this directory does not
exist, you can add it.
Yo u c a n p u t .class files
in here and they will be
found automatically
ext
...others
This is for storing .jar
files containing
extensions to the
standard packages.
You can put your own
.jar archives in here and
they will be found
automatically
JDK Directory Structure
The classes and packages in the .jar archives that you place in the ext directory will automatically be
accessible when you compile or run your Java programs, without the need to set the CLASSPATH
environment variable, or to use the -classpath command line option. When you create a .jar file
for a package, you need to make sure that you add the .class files with the directory structure
corresponding to the package name - you can't just add the .class files to the archive. For example,
suppose we want to store our Geometry package in an archive. Assuming we have already compiled
the package and the current directory contains the package directory, the following command can be
used to create the archive:
C:\JavaStuff> jar cvf Geometry.jar Geometry\*.class
This will create the archive Geometry.jar , and add all the .class files that are in the Geometry
directory to it. All you now need to do, to make the package available to any program that needs it is to
copy it, to the ext directory in the JDK directory hierarchy.
The diagram above also shows the classes directory, which may not be created by default. You can
put .class files in this directory and they will be found automatically when a program uses the classes
they contain.
Adding Classes from a Package to Your Program
Assuming they have been defined with the public keyword, you can add all or any of the classes in a
package to the code in your program by using an import statement . You can reference the classes that
you make available to your program using the import statement just by using the class names. For
example, to make available all the classes in the package Geometry.Shapes3D to a source file, you
just need to add the following import statement to the beginning of the file:
import Geometry.Shapes3D.*; // Include all classes from this package
Search WWH ::




Custom Search