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, ...
Get Java Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.