Deploying Programs

I checked out Java in Easy Steps from the local public library. After scanning the table of contents, I jumped straight to the chapter on deploying programs. This is an area of weakness for me in Java development. There are two ways to distribute Java programs. You can do so as a desktop application, which will require the Java Runtime Environment to be installed. Or you can do so as a web page applet. The second option will require the browser to have a Java plugin.

When rolling out a Java program, like any other installation, you need to make sure the resources required by the program are installed. The main way to include all the files you need is with a jar. Jar is a utility included in the Java SDK. You can find the program in the Java bin directory. This program has a command line interface.

The output of the jar utility is an archive file. You can run the program contained in the archive using the Java interpreter. Here is an example to create a jar file:

jar cf dL1.jar dL1.class.

Once you have the archive, you can inspect its contents using the following command:

jar tf dL1.jar

You can extract the full contents of the jar file like this:

jar xf dL1.jar

Jar creates a META-INF directory. Within that directory is the MANIFEST.MF file, also created by jar. You need to manually add the entry point for the program on the bottom line of that file as so:

Main-class: dL1

To run the program contained in the jar, you can execute the following command:

java –jar dL1.jar