Create a Package - .jar File

A package is a group of classes in the same directory. To construct a package:-
  1. Chose a name for the package, for example myPackage.
  2. Create a directory called myPackage.
  3. Place the .java files into the directory.
  4. Edit each .java file so that the first line reads:-
            package myPackage
  5. Compile all the files in the directory.
  6. Create a .jar file of your package as outlined in the following instructions.
  7. Open a DOS box and change to the directory above myPackage.
  8. Type in the following command to create a file called myPackage.jar:-
            jar cf myPackage.jar myPackage
  9. Copy myPackage.jar into your Java library:-
            c:\ {java version} \jre\lib\ext\
            e.g. c:\jdk1.4\jre\lib\ext\
  10. You can now use the classes in the package anywhere on your computer by importing the package:
            Import myPackage.*;

To add an entry or request an existing one to be altered, please fill in the comments form

Return to Top

About Java

Main Index

(c) Compiled by B V Wood.

 Main Index