aspose file tools
The moose likes Beginning Java and the fly likes Please explain jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Please explain jar files" Watch "Please explain jar files" New topic
Author

Please explain jar files

Kathy Lynch
Greenhorn

Joined: Feb 26, 2001
Posts: 25
Can someone please explain to me exactly what a jar file is? I was given a jar file to look at some code someone had but it is several class files, not source! Should you be able to extract source code from this somehow?
Thanks for explaining!
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
My "class to java" question is similar. A jar file is a compilation of several class files. You can look at them individually using WinZip. Consider a jar file exactly as you would a zip file. However, my question also revolves around actually seeing the source code if you only have the jar available.
Let's see if anyone can help.
Kathy Lynch
Greenhorn

Joined: Feb 26, 2001
Posts: 25
I noticed that as soon as I posted mine...if I come up with an answer then I will certainly post to your question!
John M. Gabriele
Ranch Hand

Joined: Feb 18, 2001
Posts: 232
i'm pretty sure it goes like this: suppose you write this big
program with lots of .class files and you want to sell it or
give it to your friend on a floppy. instead of giving them a
bunch of class files and subdirectories of more class files,
you just use the jar utility to jam 'em all into a "jar file".
then, you give this jar file to your friend and tell them, to
run it type
java -jar coolFile.jar
and off it goes.
some folks don't use the jar utility as i've described above but
instead just use it exactly as they would zip---to compress any
old files into one big file. in this case, if you want to un-
compress the files, you type something like
jar xvf coolFile.jar
(the x is for extract, the v is for verbose, and the f is for
"i'm gonna type in the file name for you next")
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
Does this mean you must have one (and only one) main() method throughout the entire collection of the class files in the jar file?
John M. Gabriele
Ranch Hand

Joined: Feb 18, 2001
Posts: 232
dunno. my guess is yes.
i'm new at this myself. i had just assumed you'd only put one
.class file with a main() method in with all the other .class
files in a jar.
anyone care to clarify?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
A jar file has a Manifest (in file MANIFEST.MF) that tells the JVM which class has the main that you want run. Any stray mains that happen to be in other classes (like for self-testing etc.) are ignored.

This is the sun tutorial on jar files. It covers this. http://java.sun.com/docs/books/tutorial/jar/basics/index.html


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain jar files
 
Similar Threads
Java JAR file - Can I view .java classes
confusion in if condition
understanding java libraries, jar files, classes...
Please Help!
deploying the ejb