{"id":360,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=360"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Sealing Packages within a JAR File","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=360","title":{"rendered":"Sealing Packages within a JAR File"},"content":{"rendered":"<p><DIV id=PageTitle>Sealing Packages within a JAR File<\/DIV><br \/>\n<BLOCKQUOTE>Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software.<br \/>\n<P>You seal a package in a JAR file by adding the <TT>Sealed<\/TT> header in the manifest, which has the general form: <\/P><br \/>\n<BLOCKQUOTE><PRE>Name: myCompany\/myPackage\/<br \/>\nSealed: true<br \/>\n<\/PRE><\/BLOCKQUOTE>The value <TT>myCompany\/myPackage\/<\/TT> is the name of the package to seal.<br \/>\n<P><\/P><br \/>\n<P>Note that the package name must end with a &#8220;\/&#8221;. <\/P><\/BLOCKQUOTE><br \/>\n<H3>An Example<\/H3><br \/>\n<BLOCKQUOTE>We want to seal two packages <TT>firstPackage<\/TT> and <TT>secondPackage<\/TT> in the JAR file <TT>MyJar.jar<\/TT>.<br \/>\n<P>We first create a text file named <TT>Manifest.txt<\/TT> with the following contents: <\/P><br \/>\n<BLOCKQUOTE><PRE>Name: myCompany\/firstPackage\/<br \/>\nSealed: true<\/p>\n<p>Name: myCompany\/secondPackage\/<br \/>\nSealed: true<br \/>\n<\/PRE><\/BLOCKQUOTE><br \/>\n<BLOCKQUOTE><br \/>\n<HR><br \/>\n<STRONG><FONT color=red>Warning<\/FONT> :<\/STRONG>&nbsp;<br \/>\n<P><\/P>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>We then create a JAR file named <TT>MyJar.jar<\/TT> by entering the following command:<br \/>\n<BLOCKQUOTE><PRE>jar cmf 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 \/>\nCreated-By: 1.6.0 (Sun Microsystems Inc.)<br \/>\nName: myCompany\/firstPackage\/<br \/>\nSealed: true<br \/>\nName: myCompany\/secondPackage\/<br \/>\nSealed: true<br \/>\n<\/PRE><\/BLOCKQUOTE><\/BLOCKQUOTE><br \/>\n<H3>Sealing JAR Files<\/H3><br \/>\n<BLOCKQUOTE><br \/>\n<P>If you want to guarantee that all classes in a package come from the same code source, use JAR sealing. A sealed JAR specifies that all packages defined by that JAR are sealed unless overridden on a per-package basis.<\/P><br \/>\n<P>To seal a jar file, use the <TT>Sealed<\/TT> manifest header with the value true. For example,<\/P><br \/>\n<BLOCKQUOTE><PRE>Sealed: true<\/PRE><\/BLOCKQUOTE>specifies that all packages in this archive are sealed unless explicitly overridden for particular packages with the <TT>Sealed<\/TT> attribute in a manifest entry.<\/BLOCKQUOTE><br \/>\n<DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sealing Packages within a JAR File Packages within JAR files can be optionally sealed, which means that all classes defined in that package must be archived in the same JAR file. You might want to seal a package, for example, to ensure version consistency among the classes in your software. You seal a package in &hellip; <a href=\"https:\/\/www.strongd.net\/?p=360\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Sealing Packages within a JAR File<\/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-360","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/360","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=360"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/360\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}