Creating a JAR

The jar program creates JAR files; it is part of the Java Development Kit freeware distributed by JavaSoft. To define SimpleBean as a Java Bean, I place it in a JAR by using the following command.

jar cfm SimpleBean.jar SimpleBean.man coyote\bean\SimpleBean.class

The cfm parameter tells jar to create a new file with a specific name and manifest. Issued at an MS-DOS prompt, the command above will create a new JAR file named SimpleBean.jar that contains the manifest SimpleBean.man that, in turn, describes the class coyote.bean.SimpleBean. The SimpleBean manifest is a text file that contains the following information.

Manifest-Version: 1.0

Name: coyote/bean/SimpleBean.class
Java-Bean: true

That’s it! The class is now packaged and ready for use. But how is a Java Bean used? When a Java application executes, the Java virtual machine begins searching for the required classes in the directories defined by the CLASSPATH. In this search, a Bean is treated like any other Java class; it resides in a specific directory and is located and loaded through the usual mechanisms. So why go through all the rigmarole of putting the Bean into a JAR? Wouldn’t it be easier to make SimpleBean a plain old class?

© 1997 by Scott Ladd. All rights reserved.