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. -
Creating a New JARNavigate to the directory in which you want to create the JAR. -
Type the following at the command line: jar cf myJar *.class Adding All of the Files in a Directory to the JAR -
Navigate to the directory in which you have the JAR. -
Type the following at the command line: jar cvf myApp.jar Extracting the Contents of a JAR | 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. | | -
Navigate to the directory in which you have the JAR. -
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). |