• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Please explain jar files  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that as soon as I posted mine...if I come up with an answer then I will certainly post to your question!
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!