I am currently learning about the use of and how to implement jar files , when a jar file is created is it solely for portability of code and space reduction , or can a jar file actually be used within an application as a jar file , when I read the explanation I have in front of me it does`nt really expand on the uses . I`m just taught about creating a file checking it`s directory , updating it`s contents and extracting.my guess is that it used to speed the delivery of files from point A to point B across across the web , but am unsure that it is just for this reason .Would someone be kind enough to give an account of what jar files uses are , or where I can obtain a more thorough explanation
Thanks Danny [ August 19, 2005: Message edited by: Daniel .J.Hyslop ]
an island in the sun <br />with a language of many tongue?
A jar file is a file bucket not unlike zip or a unix tar file � the etymological progenitor of jar. Serves the same purpose as a zip file: bundling files and folders in a compact format.
A jar file may, additionally, contain executable classes � classes with a public static void main(String args) method to be precise. You can tell Java to execute a the main method of a class within the jar without unbundling it first. That can be rather convenient at times.
In this example, there is an implicit class that is run within acme.jar. I'm passing launch 10:00 canyon as arguments to the main method of the unknown class:
java -jar acme.jar launch 10:00 canyon
The class is implicit because it's name is in the jar manifest, like a ship's manifest. You need this in acme.mf to execute rocket.class:
Manifest-Version: 1.0 Main-Class: rocket
OK, now you'll want to know about the manifest. When you create the jar, specifiy the name of the manifest with the m option. Example:
jar -cfm acme.jar acme.mf *.class
You can call the jar and manifest anything you like of course. [ August 19, 2005: Message edited by: Rick O'Shay ]
That was pretty interesting Rick. Any good links ?
Joined: Sep 19, 2004
Links for jars? I'm sure you could net something with a google sweep but there isn't that much to say about jars outside of a few explanatory lines. The core concept is that they are zip-like files with an optional designated main class. The other interesting issue, that I did not mention to keep it simple, is that you can chain jar dependencies using the Class-Path: xxx.jar setting in the manifest file. There isn't a whole lot else to say about 'em.