Without sealing, a "hostile" program could create a class and define it to be a member of one of your extension packages. The hostile software would then have free access to package-protected members of your extension package.
Sealing packages in extensions is no different than sealing any JAR-packaged classes. To seal your extension packages, you must add the Sealed header to the manifest of the JAR file containing your extension. You can seal individual packages by associating a Sealed header with the packages' Name headers. A Sealed header not associated with an individual package in the archive signals that all packages are sealed. Such a "global" Sealed header is overridden by any Sealed headers associated with individual packages. The value associated with the Sealed header is either true or false.
Let's look at a few sample manifest files. For these examples suppose that the JAR file contains these packages:
com/myCompany/package_1/ com/myCompany/package_2/ com/myCompany/package_3/ com/myCompany/package_4/
Suppose that you want to seal all the packages. You could do so by simply adding an archive-level Sealed header to the manifest like this:
Manifest-Version: 1.0 Sealed: true
If you wanted to seal only com.myCompany.package_3, you could do so with this manifest:
Manifest-Version: 1.0 Name: com/myCompany/package_3/ Sealed: true
For a final example, suppose that you wanted to seal all packages except for com.myCompany.package_2. You could accomplish that with a manifest like this:
Manifest-Version: 1.0 Sealed: true Name: com/myCompany/package_2/ Sealed: false