{"id":370,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=370"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Using JAR Files: The Basics","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=370","title":{"rendered":"Using JAR Files: The Basics"},"content":{"rendered":"<p><DIV><br \/>\n<DIV id=PageTitle>Using JAR Files: The Basics<\/DIV><br \/>\n<BLOCKQUOTE>JAR files are packaged with the ZIP file format, so you can use them for tasks such as lossless data compression, archiving, decompression, and archive unpacking. These tasks are among the most common uses of JAR files, and you can realize many JAR file benefits using only these basic features.<br \/>\n<P>Even if you want to take advantage of advanced functionality provided by the JAR file format such as electronic signing, you`ll first need to become familiar with the fundamental operations. <\/P><br \/>\n<P>To perform basic tasks with JAR files, you use the Java<FONT size=-2><SUP>TM<\/SUP><\/FONT> Archive Tool provided as part of the Java Development Kit. Because the Java Archive tool is invoked by using the <TT>jar<\/TT> command, this tutorial refers to it as `the Jar tool`. <\/P><br \/>\n<P>As a synopsis and preview of some of the topics to be covered in this section, the following table summarizes common JAR file operations: <\/P><br \/>\n<P><br \/>\n<TABLE cellPadding=5 border=1><br \/>\n<CAPTION><STRONG>Common JAR file operations <\/STRONG><\/CAPTION><br \/>\n<TBODY><br \/>\n<TR><br \/>\n<TH>Operation<\/TH><br \/>\n<TH>Command<\/TH><\/TR><br \/>\n<TR><br \/>\n<TD>To create a JAR file<\/TD><br \/>\n<TD><TT>jar cf <I>jar-file input-file(s)<\/I><\/TT><\/TD><\/TR><br \/>\n<TR><br \/>\n<TD>To view the contents of a JAR file<\/TD><br \/>\n<TD><TT>jar tf <I>jar-file<\/I><\/TT><\/TD><\/TR><br \/>\n<TR><br \/>\n<TD>To extract the contents of a JAR file<\/TD><br \/>\n<TD><TT>jar xf <I>jar-file<\/I><\/TT><\/TD><\/TR><br \/>\n<TR><br \/>\n<TD>To extract specific files from a JAR file<\/TD><br \/>\n<TD><TT>jar xf <I>jar-file archived-file(s)<\/I><TT><\/TT><\/TT><\/TD><\/TR><br \/>\n<TR><br \/>\n<TD>To run an application packaged as a JAR file (requires the <A href=\"http:\/\/www.strongd.net\/blog\/show\/362\"><TT>Main-class<\/TT><\/A> manifest header)<\/TD><br \/>\n<TD vAlign=center><PRE>java -jar <I>app.jar<\/I><\/PRE><\/TD><\/TR><br \/>\n<TR><br \/>\n<TD>To invoke an applet packaged as a JAR file<\/TD><br \/>\n<TD vAlign=center><PRE>&lt;applet code=<EM>AppletClassName.class<BR><\/EM>archive=&#8221;<EM>JarFileName.jar<\/EM>&#8220;<BR>width=<EM>width<\/EM> height=<EM>height<\/EM>&gt;&lt;\/applet&gt;<\/PRE><\/TD><\/TR><\/TBODY><\/TABLE><\/P><br \/>\n<P>This section shows you how to perform the most common JAR-file operations, with examples for each of the basic features: <\/P><\/BLOCKQUOTE><br \/>\n<H3><A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/365\" target=_top>Creating a JAR File<\/A><\/H3><br \/>\n<BLOCKQUOTE>This section shows you how to use the Jar tool to package files and directories into a JAR file. <\/BLOCKQUOTE><br \/>\n<H3><A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/366\" target=_top>Viewing the Contents of a JAR File<\/A><\/H3><br \/>\n<BLOCKQUOTE>You can display a JAR file`s table of contents to see what it contains without actually unpacking the JAR file. <\/BLOCKQUOTE><br \/>\n<H3><A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/367\" target=_top>Extracting the Contents of a JAR File<\/A><\/H3><br \/>\n<BLOCKQUOTE>You can use the Jar tool to unpack a JAR file. When extracting files, the Jar tool makes copies of the desired files and writes them to the current directory, reproducing the directory structure that the files have in the archive. <\/BLOCKQUOTE><br \/>\n<H3><A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/368\" target=_top>Updating a JAR File<\/A><\/H3><br \/>\n<BLOCKQUOTE>This section shows you how to update the contents of an existing JAR file by modifying its manifest or by adding files. <\/BLOCKQUOTE><br \/>\n<H3><A class=TutorialLink href=\"http:\/\/www.strongd.net\/blog\/show\/369\" target=_top>Running JAR-Packaged Software<\/A><\/H3><br \/>\n<BLOCKQUOTE>This section shows you how to invoke and run applets and applications that are packaged in JAR files. <\/BLOCKQUOTE><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using JAR Files: The Basics JAR files are packaged with the ZIP file format, so you can use them for tasks such as lossless data compression, archiving, decompression, and archive unpacking. These tasks are among the most common uses of JAR files, and you can realize many JAR file benefits using only these basic features. &hellip; <a href=\"https:\/\/www.strongd.net\/?p=370\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using JAR Files: The Basics<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=370"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/370\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}