⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 14_4.htm

📁 翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Weng Kai">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.01 [en] (Win95; I) [Netscape]">
   <TITLE>Packaging a Bean</TITLE>
</HEAD>
<BODY>

<H2>
14.4 Packaging a Bean</H2>

<HR WIDTH="100%">
<BR>Before you can bring a Bean into a Bean-enabled visual builder tool,
it must be put into the standard Bean container, which is a JAR (Java ARchive)
file that includes all the Bean classes as well as a "manifest" file that
says "This is a Bean." A manifest file is simply a text file that follows
a particular form. For the BangBean, the manifest file looks like this:
<UL>
<PRE>Manifest-Version: 1.0</PRE>

<PRE>Name: BangBean.class</PRE>

<PRE>Java-Bean: True</PRE>
</UL>
The first line indicates the version of the manifest scheme, which until
further notice from Sun is 1.0. The second line (empty lines are ignored)
names the BangBean.class file, and the third says, "It's a Bean." Without
the third line, the program builder tool will not recognize the class as
a Bean.

<P>The only tricky part is that you must make sure that you get the proper
path in the "Name:" field. If&nbsp; it's in package such as named bangbean
(and thus in a subdirectory called "bangbean" that's off of the classpath),
and the name in the manifest file must include this package information.
In addition, you must place the manifest file in the directory above the
root of your package path, which in this case means placing the file in
the directory above the "bangbean" subdirectory. Then you must invoke jar
from the same directory as the manifest file, as follows:
<UL>
<PRE>jar cfm BangBean.jar BangBean.mf bangbean</PRE>
</UL>
This assumes that you want the resulting JAR file to be named BangBean.jar
and that you've put the manifest in a file called BangBean.mf.

<P>You might wonder "What about all the other classes that were generated
when I compiled BangBean.java?" Well, they all ended up inside the bangbean
subdirectory, and you'll see that the last argument for the above jar command
line is the bangbean subdirectory. When you give jar the name of a subdirectory,
it packages that entire subdirectory into the jar (including, in this case,
the original BangBean.java source-code file -- you might not choose to
include the source with your own Beans). In addition, if you turn around
and unpack the JAR file you've just created, you'll discover that your
manifest file isn't inside, but that jar has created its own manifest file
(based partly on yours) called MANIFEST.MF and placed it inside the subdirectory
META-INF (for "meta-information"). If you open this manifest file you'll
also notice that digital signature information has been added by jar for
each file, of the form:
<UL>
<PRE>Digest-Algorithms: SHA MD5</PRE>

<PRE>SHA-Digest: pDpEAG9NaeCx8aFtqPI4udSX/O0=</PRE>

<PRE>MD5-Digest: O4NcS1hE3Smnzlp2hj6qeg==</PRE>
</UL>
In general, you don't need to worry about any of this, and if you make
changes you can just modify your original manifest file and re-invoke jar
to create a new JAR file for your Bean. You can also add other Beans to
the JAR file simply by adding their information to your manifest.

<P>One thing to notice is that you'll probably want to put each Bean in
its own subdirectory, since when you create a JAR file you hand the jar
utility the name of a subdirectory and it puts everything in that subdirectory
into the JAR file. You can see that both Frog and BangBean are in their
own subdirectories.

<P>Once you have your Bean properly inside a JAR file you can bring it
into a Beans-enabled program-builder environment. The way you do this varies
from one tool to the next, but Sun provides a freely-available test bed
for Java Beans in their "Beans Development Kit" (BDK) called the "beanbox."
(Download the BDK from www.javasoft.com.) To place your Bean in the beanbox,
copy the JAR file into the BDK's "jars" subdirectory before you start up
the beanbox.

<P>
<HR WIDTH="100%">
<CENTER>The End</CENTER>
<HR WIDTH="100%">
<DIV ALIGN=right><A HREF="../Lesson15/15.html">Next Page</A></DIV>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -