Ved International Discussion Board

Sealing A Jar File

Go down

Sealing A Jar File Empty Sealing A Jar File

Post by jp2012 on Sun Jul 21, 2013 7:22 am

The class path causes many Java-induced headaches. One of the problems with the class path is that multiple versions of the same class or classes can be in the class path at the same time. The virtual machine will load the first one it finds. There are times in which you cannot avoid this situation, such as when your application is running in a container. Sealed jars offer a partial remedy for this problem.

When you use sealed jars in your application, the class loader will ensure that all classes in the same package load from the same jar file. For example, say that class com.acme.A loads from the sealed file acme.jar. Later, the class loader is told to load the class com.acme.B. Since A and B are in the same package, the class loader attempts to load class B from acme.jar. If class B cannot be found in acme.jar but can be found elsewhere, then a Security Exception is thrown.

Sealing a jar is as simple as providing an entry in the jar's manifest file. To create a sealed jar that contained all of the classes in the com directory and its subdirectories package, here's how the command would look:

jar cmf mymanifest.txt myjar.jar com

where mymanifest.txt contains:

Manifest-Version: 1.0
Sealed: true

The whole jar is now considered sealed by the class loaders that use it.

Sealing your jars won't solve all of your class path problems, but it can be helpful. This is also a good habit to develop, so start making sealed jars part of your deployment system. There are more options for sealing; for instance, you can seal some packages and not others.
jp2012
jp2012
Worker
Worker

Posts : 145
Join date : 2013-06-30
Location : Japan

Back to top Go down

Sealing A Jar File Empty Re: Sealing A Jar File

Post by brayan.karki on Sun Oct 06, 2013 12:56 pm

* WAR (file format) (Web Application aRchive) files are also Java archives which store XML files, java classes, Java Server Pages and other objects for Web Applications.
* JAR file (or Java ARchive) is a ZIP file used to distribute a set of Java classes. It is used to store compiled Java classes and associated metadata that can constitute a program.
brayan.karki
brayan.karki
Achiever
Achiever

Posts : 383
Join date : 2011-08-01
Age : 26
Location : Dhapakhel-2,lalitpur

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum