📄 tij0115.html
字号:
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">A
JAR file consists of a single file containing a collection of zipped files
along with a “<A NAME="Index1301"></A>manifest”
that describes them. (You can create your own manifest file; otherwise the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar
</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">program
will do it for you.) You can find out more about JAR manifests in the online
documentation.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
utility that comes with Sun’s JDK automatically compresses the files of
your choice. You invoke it on the command line:
</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
[options] destination [manifest] inputfile(s)
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
options are simply a collection of letters (no hyphen or any other indicator is
necessary). These are:
</FONT><P></DIV>
<DIV ALIGN=LEFT><TABLE BORDER>
<COLGROUP>
<COL width="36">
<COL width="301">
</COLGROUP>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>c</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
</FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Creates
a new or empty archive.
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>t</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
</FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Lists
the table of contents.
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>x</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Extracts
all files
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>x
file
</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Extracts
the named file
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>f</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Says:
“I’m going to give you the name of the file.” If you
don’t use this,
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar
</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">assumes
that its input will come from standard input, or, if it is creating a file, its
output will go to standard output.
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>m</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Says
that the first argument will be the name of the user-created manifest file
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>v</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Generates
verbose output describing what
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
is doing
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>O</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Only
store the files; doesn’t compress the files (use to create a JAR file
that you can put in your classpath)
</FONT><P></DIV>
</TD>
</TR>
<TR VALIGN="TOP">
<TD WIDTH=36 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>M</B></FONT><P></DIV>
</TD>
<TD WIDTH=301 COLSPAN=1 ROWSPAN=1 VALIGN=TOP>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Don’t
automatically create a manifest file
</FONT><P></DIV>
</TD>
</TR>
</TABLE></DIV>
<DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">If
a subdirectory is included in the files to be put into the JAR file, that
subdirectory is automatically added, including all of its subdirectories, etc.
Path information is also preserved.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Here
are some typical ways to invoke
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">:</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
cf myJarFile.jar *.class
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">This
creates a JAR file called
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>myJarFile.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
that contains all of the class files in the current directory, along with an
automatically-generated manifest file.
</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
cmf myJarFile.jar myManifestFile.mf *.class
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Like
the previous example, but adding a user-created manifest file called
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>myManifestFile.mf</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
tf myJarFile.jar
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Produces
a table of contents of the files in
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>myJarFile.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
tvf myJarFile.jar
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Adds
the “verbose” flag to give more detailed information about the
files in
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>myJarFile.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">jar
cvf myApp.jar audio classes image
</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Assuming
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>audio</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">,
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>classes,</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
and
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>image</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
are subdirectories, this combines all of the subdirectories into the file
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>myApp.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">.
The “verbose” flag is also included to give extra feedback while the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
program is working.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">If
you create a JAR file using the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>O</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
option, that file can be placed in your CLASSPATH:
</FONT><P></DIV><DIV ALIGN=LEFT><TT><FONT FACE="Courier New" SIZE=3 COLOR="Black">CLASSPATH="lib1.jar;lib2.jar;"</FONT></TT><P></DIV><DIV ALIGN=LEFT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">Then
Java can search
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>lib1.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
and
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>lib2.jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
for class files.
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">The
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
tool isn’t as useful as a
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>zip</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
utility. For example, you can’t add or update files to an existing JAR
file; you can create JAR files only from scratch. Also, you can’t move
files into a JAR file, erasing them as they are moved. However, a JAR file
created on one platform will be transparently readable by the
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>jar</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
tool on any other platform (a problem that sometimes plagues
</FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black"><B>zip</B></FONT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">
utilities).
</FONT><P></DIV><DIV ALIGN=LEFT><FONT FACE="Carmina Md BT" SIZE=3 COLOR="Black">As
you will see in Chapter 13, JAR files are also used to package Java Beans.
</FONT><a name="_Toc408018638"></a><P></DIV>
<div align="right">
<a href="tij_c.html">Contents</a> | <a href="tij0114.html">Prev</a> | <a href="tij0116.html">Next</a>
</div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -