*
The moose likes Beginning Java and the fly likes Jar file uses? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jar file uses?" Watch "Jar file uses?" New topic
Author

Jar file uses?

Daniel .J.Hyslop
Ranch Hand

Joined: May 23, 2005
Posts: 55
Hello there,

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?
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
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 ]
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
That was pretty interesting Rick. Any good links ?

Arnab
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
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.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
There is even a tutorial from Sun about jar files.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar file uses?
 
Similar Threads
jar and RMI don�t work?
Help with JarURLConnection
Creating a new file type in NetBeans
Read contents of jar file given specific path
War with WAR, EAR and JAR