Working with JAR Files

     

A JAR file (Java ARchive) uses the same algorithm as a Zip utility does to compress numerous documents into one archive document. The benefit of a .jar file is that the developer can combine HTML, applets, class files, images, sounds, and everything else that makes up an application, and put them all into a JAR to facilitate easy distribution of the application. The jar tool is a Java application tool, regularly available with the SDK.

Note that you can add v to the command-line call options for verbose output, to indicate what is happening while your JAR is being created.

  1. Creating a New JARNavigate to the directory in which you want to create the JAR.

  2. Type the following at the command line:

     

     jar cf myJar *.class 

Adding All of the Files in a Directory to the JAR

  1. Navigate to the directory in which you have the JAR.

  2. Type the following at the command line:

     

     jar cvf myApp.jar 

Extracting the Contents of a JAR

graphics/fridge_icon.jpg

FRIDGE

If you type the jar command and, instead of working, Windows tells you something like, "'jar' is not recognized as an internal or external command, operable program, or batch file," it means that the system cannot find the jar program to run it. So we have to put the jar program on the path (the list of places that Windows goes to find things to execute). We do this by setting the PATH environment variable to include the location of your bin directory (<JAVA_HOME>\bin ), because that's where the jar program lives.


  1. Navigate to the directory in which you have the JAR.

  2. Type the following at the command line:

     

     jar -xvf myApp.jar 

You should see the program extracting the files into the pwd (Present Working Directory).



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net