Tutorials

Create a JAR file for a Java Applet

Step 1: Create a JAR file for a Java Applet

Create the JAR file

On the command line, in the directory where your assignment is located, type:

jar -cfv LabName.jar Labxx.*

This statement will create a file called LabName.jar which contains all of the files in the current directory whose names begin with Labxx (Labxx.java and Labxx.class). If there are oher files which also need to be inlcuded in the JAR file whose names do not being with Labxx then the names of the additional files can be written after Labxx.* on the command line.

jar -cfv LabName.jar Labxx.* otherFiles.*

The switch 'cfv' tell the JAR command to 'C'reate a 'F'ile and produce 'V'erbose output of the process.

When doing this in the "Real-World" you would substitute Labxx.class for Labxx.* so that your source code would not be included where it could potentially be taken.

The HTML file you created for you applet will still work when the applet is placed in a JAR file except that the HTML file will need to have a line added specifying the archive that the applet class file will be found in. Other than this one line the rest of the HTML file will remain exactly the same.