{"id":373,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=373"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Using JAR-related APIs","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=373","title":{"rendered":"Using JAR-related APIs"},"content":{"rendered":"<p><DIV id=PageTitle>Using JAR-related APIs<\/DIV><br \/>\n<BLOCKQUOTE>The Java<FONT size=-2><SUP>TM<\/SUP><\/FONT> platform contains several classes for use with JAR files. Some of these APIs are:<br \/>\n<UL><br \/>\n<LI><A class=APILink href=\"http:\/\/java.sun.com\/javase\/6\/docs\/api\/java\/util\/jar\/package-summary.html\" target=_blank>The <TT><B>java.util.jar<\/B><\/TT> package<\/A> <\/LI><br \/>\n<LI><A class=APILink href=\"http:\/\/java.sun.com\/javase\/6\/docs\/api\/java\/net\/JarURLConnection.html\" target=_blank>The <TT><B>java.net.JarURLConnection<\/B><\/TT> class<\/A> <\/LI><br \/>\n<LI><A class=APILink href=\"http:\/\/java.sun.com\/javase\/6\/docs\/api\/java\/net\/URLClassLoader.html\" target=_blank>The <TT><B>java.net.URLClassLoader<\/B><\/TT> class<\/A> <\/LI><\/UL><br \/>\n<P>To give you an idea of the possibilities that are opened up by these new APIs, this lesson guides you through the inner workings of a sample application called JarRunner. <\/P><\/BLOCKQUOTE><br \/>\n<H3>An Example &#8211; The JarRunner Application<\/H3><br \/>\n<BLOCKQUOTE>JarRunner enables you to run an application that&#8217;s bundled in a JAR file by specifying the JAR file&#8217;s URL on the command line. For example, if an application called <TT>TargetApp<\/TT> were bundled in a JAR file at <TT>http:\/\/www.xxx.yyy\/TargetApp.jar<\/TT>, you could run the application using this command:<br \/>\n<BLOCKQUOTE><PRE>java JarRunner http:\/\/www.xxx.yyy\/TargetApp.jar<br \/>\n<\/PRE><\/BLOCKQUOTE>In order for JarRunner to work, it must be able to perform the following tasks, all of which are accomplished by using the new APIs:<br \/>\n<UL><br \/>\n<LI>Access the remote JAR file and establish a communications link with it. <\/LI><br \/>\n<LI>Inspect the JAR file&#8217;s manifest to see which of the classes in the archive is the main class. <\/LI><br \/>\n<LI>Load the classes in the JAR file. <\/LI><\/UL><br \/>\n<P>The JarRunner application consists of two classes, <TT>JarRunner<\/TT> and <TT>JarClassLoader<\/TT>. <TT>JarRunner<\/TT> delegates most of the JAR-handling tasks to the <TT>JarClassLoader<\/TT> class. <TT>JarClassLoader<\/TT> extends the <TT>java.net.URLClassLoader<\/TT> class. You can browse the source code for the <TT>JarRunner<\/TT> and <TT>JarClassLoader<\/TT> classes before proceeding with the lesson: <\/P><br \/>\n<UL><br \/>\n<LI><A class=SourceLink href=\"http:\/\/java.sun.com\/docs\/books\/tutorial\/deployment\/jar\/examples\/JarRunner.java\" target=_blank><CODE>JarRunner.java<\/CODE><\/A> <\/LI><br \/>\n<LI><A class=SourceLink href=\"http:\/\/java.sun.com\/docs\/books\/tutorial\/deployment\/jar\/examples\/JarClassLoader.java\" target=_blank><CODE>JarClassLoader.java<\/CODE><\/A> <\/LI><\/UL><br \/>\n<P>This lesson has two parts: <\/P><br \/>\n<H3><A href=\"http:\/\/www.strongd.net\/blog\/show\/371\">The JarClassLoader Class<\/A><\/H3><br \/>\n<BLOCKQUOTE>This section shows you how <TT>JarClassLoader<\/TT> uses some of the new APIs to perform tasks required for the JarRunner application to work. <\/BLOCKQUOTE><br \/>\n<H3><A href=\"http:\/\/www.strongd.net\/blog\/show\/372\">The JarRunner Class<\/A><\/H3><br \/>\n<BLOCKQUOTE>This section summarizes the <TT>JarRunner<\/TT> class that comprises the JarRunner application. <\/BLOCKQUOTE><\/BLOCKQUOTE><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using JAR-related APIs The JavaTM platform contains several classes for use with JAR files. Some of these APIs are: The java.util.jar package The java.net.JarURLConnection class The java.net.URLClassLoader class To give you an idea of the possibilities that are opened up by these new APIs, this lesson guides you through the inner workings of a sample &hellip; <a href=\"https:\/\/www.strongd.net\/?p=373\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using JAR-related APIs<\/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-373","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/373","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=373"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/373\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}