touque.ca > Education Commons > Java > Resources

JARs

“JAR files are packaged with the zip file format, so you can use them for tasks such as lossless data compression, archiving, decompression, and archive unpacking. These tasks are among the most common uses of JAR files, and you can realize many JAR file benefits using only these basic features.

“To perform basic tasks with JAR files, you use the Java Archive Tool provided as part of the Java Development Kit (JDK). The Java Archive tool is invoked by using the jar command.” (Abridged from Lesson: Packaging Programs in JAR Files; see Resources below.)

Create a stand-alone application

To create a stand-alone application (a JAR), ensure that at least one of your classes contains a main method with the standard signature:

public static void main(String[] argument)

The instructions which follow assume:

Of course, you should modify the instructions to reflect the circumstances of your particular application.

Create the JAR

At the command line of your operating system, navigate to the single directory which contains your Java application and type the following command:

jar cvfe HelloWorld.jar HelloWorld *.class images sounds

Here’s the breakdown of the command:

To execute the JAR file from the command prompt, type:

java -jar HelloWorld.jar

to execute the JAR file from your operating system’s GUI, double-click it.

Resources

The Java Tutorials: Lesson: Packaging Programs in JAR Files

touque.ca > Education Commons > Java > Resources

[This page last updated 2020-12-23 at 12h13 Toronto local time.]