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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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.