|
|
|
|
When you wish to add a Java Bean to the BeanBox, or (most likely) to any other similar tool, you have to deploy it properly. This means adding all the files that the Bean uses (.class files, .gif files, etc) into a Java Archive, or jar, file. The jar ProgramThe jar program is provided as part of the JavaSoft JDK. Like most other programs supplied with the JDK, it has a UNIX-style command line interface, which is not particularly user-friendly. Most Java IDE vendors also provide it (or something equivalent), but usually implement an easier interface to it from their IDE. The BDK has a number of examples of make files (usually UNIX-only) which you can use as models for constructing your own make files for your own Java Beans. Using make is usually far preferable to learning such arcane interfaces. The command line interface looks like:
The first command line argument consists of a set of single-character options. One, and only one, of the required command options (c, t, or x) may be selected at a time. The remainder of the options may be combined or omitted, as necessary.
The optional jar-file argument specifies the name of the archive file. If you use the f option, this argument should be present. Note that (as is true for many UNIX utilities), there are no required naming rules for jar files. In particular, if you wish a .jar filetype, you must be explicit about it. The optional manifest-file argument specifies the name of a file that contains the manifest information to be used for the archive. If you use the m option, this argument should be present. For details on the contents of this manifest file, see The Manifest, below. After the jar-file and manifest-file arguments, follow the filenames to be archived. Multiple filenames are separated by whitespace, and you can use wildcards, as needed. You may not remove an entry from, nor add an entry to, an existing JAR file -- each time you want to do that, you must recreate the entire file. ExamplesCreating a jar FileThe command: jar cf MyBean.jar MyBean.class (when executed in the directory where the MyBean.class file exists) creates a new archive, MyBean.jar, containing the file MyBean.class. Another example: jar cvf BeanLibrary.jar myBeans/classes/*.class creates a new archive, BeanLibrary.jar, containing all the .class files in the myBeans/classes subdirectory of the directory from where the command is executed. The v option causes something like: adding: myBeans/classes/FromageDistributorBean.class in=2999 out=1507 deflated 49.0% to be output on standard out, for each file added to the archive. Listing a jar FileThe command jar tvf ColorBar.jar will output on standard out something like:
The ManifestThe jar utility automatically generates a manifest when the archive is created, unless you specify the M option. The name of the manifest is always MANIFEST.MF and it is always placed into a directory META-INF. The manifest contains one or more sections, each one describing an entry in the archive. Sections are separated by a blank line. For example, here is the manifest for the above ColorBar.jar file:
Each section in the manifest contains a series of attribute/value pairs attribute-name: value The first section in the manifest identifies the manifest version used by the archive. Each of the subsequent sections describe an element in the archive (not including the manifest itself) Most of the information has to do with the digest algorithms and resulting hash values for the element. The most important attribute for our current purposes is: Java-Bean: True which is how the elements in the archive that are Java Beans are identified as such, by the BeanBox, and other similar programs. Specifying a Manifest FileIf you don't supply a manifest, jar will generate one for you, unless you specify the M option. If you want to specify that one or more of your classes is a Bean, then you have to create a manifest yourself. However, you don't have to describe every element, nor even all the attributes for an entry. Here's an example of what was specified when ColorBar.jar was created:
Then you can use the command (typed on a single, very long line): jar cfm ColorBar.jar ColorBar.mf javaBeans/ColorBarApplet.class javaBeans/ColorBar.class javaBeans/ColorBarApplet$1.class javaBeans/BarChart.class javaBeans/IntBox.class to create the archive file. |
| The page was last updated February 19, 2008 |