Skip to Main Content
Java Cookbook
book

Java Cookbook

by Ian F. Darwin
June 2001
Intermediate to advanced content levelIntermediate to advanced
888 pages
21h 1m
English
O'Reilly Media, Inc.
Content preview from Java Cookbook

Pickling Your Bean into a JAR

Problem

You need to package your bean for deployment.

Solution

“Pickle your bean into a JAR,” that is, create a JAR archive containing it and a manifest file.

Discussion

In addition to the compiled file, you need a manifest prototype, which needs only the following entries:

Name: LabelText.class
Java-Bean: true

If these lines are stored in a file called LabelText.stub, we can prepare the whole mess for use as a bean by running the jar command (see Section 23.4):

jar cvfm labeltext.jar LabelText.stub LabelText.class

Now we’re ready to install labeltext.jar as a JavaBean. However, the curious may wish to examine the JAR file in detail. The x option to jar asks it to extract files:

$ jar xvf *.jar
     0 Sat Nov 18 20:03:40 EST 2000 META-INF/
   106 Sat Nov 18 20:03:42 EST 2000 META-INF/MANIFEST.MF
  1829 Wed Jan 17 20:03:30 EST 2001 LabelText.class

The MANIFEST.MF file is based upon the manifest file (LabelText.stub); let’s examine it:

$ more  META-INF/MANIFEST.MF
Manifest-Version: 1.0
Name: LabelText.class
Java-Bean: true
Created-By: 1.2 (Sun Microsystems Inc.)

Not much exciting has happened besides the addition of a few lines. But the class is now ready for use as a JavaBean. For a GUI builder, either copy it into the beans directory or use the bean installation wizard as appropriate.

See Also

There are many good books available on JavaBeans technology. O’Reilly’s entry is Developing JavaBeans, by Robert Englander. You can also find information on JavaBeans at Sun’s web site, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Cloud-Native Java Development with MicroProfile

Practical Cloud-Native Java Development with MicroProfile

Emily Jiang, Andrew McCright, John Alcorn, David Chan, Alasdair Nottingham
Distributed Computing in Java 9

Distributed Computing in Java 9

Raja Malleswara Rao Malleswara Rao Pattamsetti

Publisher Resources

ISBN: 0596001703Supplemental ContentCatalog PageErrata