Applets
JAR
Create and work
What is JAR?
Java archive file can be used to group all the project files in a compressed file for deployment.
The Java archive file format (JAR) is based on the popular ZIP file format.
This single file can be deployed on an end-user's machine as an application. It also can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece. This greatly simplifies application deployment and improves the speed with which an applet can be loaded onto a web page and begin functioning.
The syntax for using the JAR tool at the command line
jar [options] JARFileName File1 File2 File3 ...
Common options of the JAR tool
Option | Description |
---|---|
c | Creates a new JAR file and adds the specified files to it. |
f | Specifies the second argument as the JAR file name. |
u | Updates an existing JAR file by adding or replacing files. |
x | Extracts the files from the specified JAR file. |
t | Lists the contents of the specified JAR file. |
v | Creates verbose output that includes compression information about the files that are stored in a JAR file. |
How to create and work with JAR files
- To use the JAR tool, start the command prompt and navigate to the directory where the files you want to archive are stored. Then, issue the JAR command.
- To operate on all the files with a given extension, you can use the wildcard character (*).
An example that creates a JAR file
C:\java1.5\ch18\FutureValue>jar cfv FutureValue.jar *.class added manifest adding: FinancialCalculations.class(in = 437) (out= 336)(deflated 23%) adding: FutureValueApplet.class(in = 452) (out= 298)(deflated 34%) adding: FutureValuePanel.class(in = 2966) (out= 1583)(deflated 46%)
An example that updates a JAR file
C:\java1.5\ch18\FutureValue>jar ufv FutureValue.jar SwingValidator.class adding: SwingValidator.class(in = 2022) (out= 1010)(deflated 50%)
An example that extracts files from a JAR file
C:\java1.5\ch18\FutureValue>jar xfv FutureValue.jar created: META-INF/ inflated: META-INF/MANIFEST.MF inflated: FinancialCalculations.class inflated: FutureValueApplet.class inflated: FutureValuePanel.class inflated: SwingValidator.class
An example that lists the contents of a JAR file
C:\java1.5\ch18\FutureValue>jar tf FutureValue.jar META-INF/ META-INF/MANIFEST.MF FinancialCalculations.class FutureValueApplet.class FutureValuePanel.class SwingValidator.class