Why seal a JAR File or why seal packages with a JAR file?
A friend told me it is good practice to seal JAR files. I asked him why and he didn't know why. Pretty fatuous if you ask me. Anyhow, three questions arise:
1. Is it good practice to seal JAR files?
2. If so, why?
3. When would one seal packages within a JAR file?
I did some reading ( Sealing Packages within a JAR File (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files) )
This is the tutorial's explanation of question #3:
Isn't the bold text always true? Is it saying that it is possible for some classes of a package can be in a different JAR file? If so, wouldn't one always seal a package then?
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.
This is the tutorial's explanation of question #2:
When will it not be in the same source? Is it talking about a package being in a different JAR file? If someone can explain, I would be grateful.
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.
Finally, is there any other reason why one should seal a JAR file or packages within it? Is it good practice to do so? Thanks in advance!