{"id":363,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=363"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Adding Classes to the JAR File's Classpath","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=363","title":{"rendered":"Adding Classes to the JAR File&#8217;s Classpath"},"content":{"rendered":"<p><DIV id=PageTitle>Adding Classes to the JAR File&#8217;s Classpath<\/DIV><br \/>\n<BLOCKQUOTE>You may need to reference classes in other JAR files from within a JAR file.<br \/>\n<P>For example, in a typical situation an applet is bundled in a JAR file whose manifest references a different JAR file (or several different JAR files) that serves as utilities for the purposes of that applet. <\/P><br \/>\n<P>You specify classes to include in the <TT>Class-Path<\/TT> header field in the manifest file of an applet or application. The <TT>Class-Path<\/TT> header takes the following form: <\/P><br \/>\n<BLOCKQUOTE><PRE>Class-Path: <EM>jar1-name jar2-name directory-name\/jar3-name<\/EM><br \/>\n<\/PRE><\/BLOCKQUOTE>By using the <TT>Class-Path<\/TT> header in the manifest, you can avoid having to specify a long <TT>-classpath<\/TT> flag when invoking Java to run the your application.<br \/>\n<P><\/P><br \/>\n<P><\/P><br \/>\n<BLOCKQUOTE><br \/>\n<HR><br \/>\n<STRONG><FONT color=red>Note<\/FONT> :<\/STRONG>&nbsp;The <TT>Class-Path<\/TT> header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if <TT>MyJar.jar<\/TT> contains another JAR file called <TT>MyUtils.jar<\/TT>, you cannot use the <TT>Class-Path<\/TT> header in <TT>MyJar.jar&#8217;s<\/TT> manifest to load classes in <TT>MyUtils.jar<\/TT> into the class path.<br \/>\n<HR><br \/>\n<\/BLOCKQUOTE><br \/>\n<P><\/P><\/BLOCKQUOTE><br \/>\n<H3>An Example<\/H3><br \/>\n<BLOCKQUOTE>We want to load classes in <TT>MyUtils.jar<\/TT> into the class path for use in <TT>MyJar.jar<\/TT>. These two JAR files are in the same directory.<br \/>\n<P>We first create a text file named <TT>Manifest.txt<\/TT> with the following contents: <\/P><br \/>\n<BLOCKQUOTE><PRE>Class-Path: MyUtils.jar<br \/>\n<\/PRE><\/BLOCKQUOTE><br \/>\n<P><\/P><br \/>\n<BLOCKQUOTE><br \/>\n<HR><br \/>\n<STRONG><FONT color=red>Warning<\/FONT> :<\/STRONG>&nbsp;The text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.<br \/>\n<HR><br \/>\n<\/BLOCKQUOTE><br \/>\n<P>We then create a JAR file named <TT>MyJar.jar<\/TT> by entering the following command: <\/P><br \/>\n<BLOCKQUOTE><PRE>jar cfm MyJar.jar Manifest.txt MyPackage\/*.class<br \/>\n<\/PRE><\/BLOCKQUOTE>This creates the JAR file with a manifest with the following contents:<br \/>\n<BLOCKQUOTE><PRE>Manifest-Version: 1.0<br \/>\nClass-Path: MyUtils.jar<br \/>\nCreated-By: 1.6.0 (Sun Microsystems Inc.)<br \/>\n<\/PRE><\/BLOCKQUOTE>The classes in <TT>MyUtils.jar<\/TT> are now loaded into the class path when you run <TT>MyJar.jar<\/TT>.<\/BLOCKQUOTE><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding Classes to the JAR File&#8217;s Classpath You may need to reference classes in other JAR files from within a JAR file. For example, in a typical situation an applet is bundled in a JAR file whose manifest references a different JAR file (or several different JAR files) that serves as utilities for the purposes &hellip; <a href=\"https:\/\/www.strongd.net\/?p=363\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Adding Classes to the JAR File&#8217;s Classpath<\/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-363","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/363","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=363"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/363\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}