Bean Deployment
Home ] Up ] What are JavaBeans? ] The Bean Development Kit ] The BeanBox ] JavaBean Properties ] Simple and Indexed Properties ] Bound Properties ] Constrained Properties ] [ Bean Deployment ] Introspection ] Property Editors ] Customizers ] Bean Persistence ] New JavaBean Features ]

 

 

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 Program

The 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:

jar {ctx}[vfm0M] [jar-file] [manifest-file] files ...

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.

Option Description
c Create a new archive file
t List the table of contents for the archive file
x Extract the named files from the archive. If no filenames are specified, all files are extracted.
v Generate verbose output
f Specify the archive filename following the options. If this option is not used, standard in and standard out are used.
m Include manifest information from the specified manifest file.
0 Do not use compression.
M Do not create a manifest file for the archive entries

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.

Examples

Creating a jar File

The 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 File

The command

jar tvf ColorBar.jar

will output on standard out something like:

   820 Sat Apr 08 13:47:00 EDT 2000 META-INF/MANIFEST.MF
     0 Sat Apr 08 13:47:00 EDT 2000 javaBeans/
  2228 Sat Apr 08 13:47:00 EDT 2000 javaBeans/IntBox.class
   944 Sat Apr 08 13:47:00 EDT 2000 javaBeans/ColorBarApplet$1.class
  3377 Sat Apr 08 13:47:00 EDT 2000 javaBeans/BarChart.class
  1745 Sat Apr 08 13:47:00 EDT 2000 javaBeans/ColorBarApplet.class
  1265 Sat Apr 08 13:47:00 EDT 2000 javaBeans/ColorBar.class

The Manifest

The 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:

Manifest-Version: 1.0

Name: javaBeans/ColorBarApplet.class
Java-Bean: True
Digest-Algorithms: SHA MD5 
SHA-Digest: dJzolmQMY/ROREoe+3g6yDek74c=
MD5-Digest: bk8bOtTGLsUXgSvGZvkVSw==

Name: javaBeans/ColorBar.class
Java-Bean: True
Digest-Algorithms: SHA MD5 
SHA-Digest: u2opYIh3iPV3I/zL1trCIAewomU=
MD5-Digest: ySp487LPYwRoH7ALDxHo5Q==

Name: javaBeans/ColorBarApplet$1.class
Digest-Algorithms: SHA MD5 
SHA-Digest: 9ZbCTRD1yj+anZSF8yqM3vCas3k=
MD5-Digest: Ptp9iNw0ME2erBbhdw2EQQ==

Name: javaBeans/BarChart.class
Java-Bean: True
Digest-Algorithms: SHA MD5 
SHA-Digest: pbVzI/6/i/AWWymh8GsAsh6LJXY=
MD5-Digest: tn8YFEskhBBXagDnQfBx8A==

Name: javaBeans/IntBox.class
Java-Bean: True
Digest-Algorithms: SHA MD5 
SHA-Digest: JMZiL+AeOOm0YDTG2TKYr/e+ZQg=
MD5-Digest: DNSTTzEtQqldicVjBh9R7w==

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 File

If 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:

Manifest-Version: 1.0

Name: javaBeans/ColorBarApplet.class
Java-Bean: True

Name: javaBeans/ColorBar.class
Java-Bean: True

Name: javaBeans/BarChart.class
Java-Bean: True

Name: javaBeans/IntBox.class
Java-Bean: True

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