This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes why are JAR files created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why are JAR files created" Watch "why are JAR files created" New topic
Author

why are JAR files created

pras
Ranch Hand

Joined: Apr 04, 2007
Posts: 188
hi people,

i know how to create JAR files. But professionaly when are they created and for what purpose?
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

That's a good question.

JAR - is an abbreviation of Java ARchive. Archive is a compressed version of many files, we can say in simple terms.

In order to have a related .class files into one archive file so that maintenance of those files into any application which is in need of it will be easy.

The purposes are
  • you can load any class from the JAR file
  • you can use it as a library reference to include the classes which are being imported into an application.



  • Does that help you?


    Everything has got its own deadline including one's EGO!
    [CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
    pras
    Ranch Hand

    Joined: Apr 04, 2007
    Posts: 188
    thanks for the information


    one more doubt, suppose i have A.class,B.class and C.class in a single JAR file which has name XYZ.jar
    then how can i get only A.class file back


    one more doubt,
    can we get the java Source code back from a single .Class File?
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19651
        
      18

    Originally posted by prasanna sheregar:
    one more doubt, suppose i have A.class,B.class and C.class in a single JAR file which has name XYZ.jar
    then how can i get only A.class file back

    JAR files are a special kind of ZIP files. Using a ZIP application, such as WinZip, TugZIP or Windows XP's built in unpacker, you can easily extract any file from a JAR file.

    one more doubt,
    can we get the java Source code back from a single .Class File?

    The original source? No. For instance, all comments will be removed, and sometimes the compiler optimizes code.

    Some decompilers do a good enough job though. I've used JADNT in the past with some good result. Still, it is never a replacement for having the original source.

    It is also possible to obfuscate compiled code. If this has occurred it is hard, if at all possible, to retrieve its source code.

    Final note: decompiling Java classes (or any program for that matter) can be illegal, depending on both the country and the origin of the compiled code.
    [ November 20, 2007: Message edited by: Rob Prime ]

    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
    How To Ask Questions How To Answer Questions
    Raghavan Muthu
    Ranch Hand

    Joined: Apr 20, 2006
    Posts: 3344

    Simply speaking, its possible through 'Decompilation' through some tools like JAD.

    But you got a detailed explanation by Rob.
    Stan James
    (instanceof Sidekick)
    Ranch Hand

    Joined: Jan 29, 2003
    Posts: 8791
    A jar is often a "unit of deployment", a bundle of related code that should be released together. In a large system we might find different subsystems and frameworks divided into different jars. And in some environments it is important to be able to deploy one new jar without updating all the others.


    A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
     
    jQuery in Action, 2nd edition
     
    subject: why are JAR files created
     
    Similar Threads
    dynamic classpath
    Need answer asap
    Difference between JAR,WAR and EAR
    How to put jar after creating it in war file's lib through Maven
    How to create a war file.