Showing posts with label Short Notes on JAR. Show all posts
Showing posts with label Short Notes on JAR. Show all posts

Monday, February 22, 2010

Short Notes on Java Archive(JAR) file

JAR:

The Java Archive (JAR) file format enables you to bundle multiple files into a single archive file. Typically a JAR file contains the class files and auxiliary resources associated with applets and applications

Advantages:

  • Security, A jar file can be digitally signed enabling users to verify the signature and then grant the program security privileges.

  • Decreased download time, since the archive is compressed it takes less time to download than it would to download each individual file.

  • Package Versioning, A Jar file may contain vendor and version information about the files it contains.

  • Portability, all Java Runtime Environments know how to handle Jar files.

Example:

  1. Making javafile and compile that

    package amir;
    public class Hello
    {
    public static void main(String arg[])
    {
    System.out.println("Hello its form Hello.java inside amir package");
    }
    }

javac Hello.java

then amir directory have amir->Hello.java

->Hello.class

  1. Creating mainclass file:
    mainclass contains below line
    Main-Class: amir.Hello

  2. Making jar files:
    jar cmf mainclass myfirst.jar amir/Hello.class
    then u will get myfirst.jar

  3. Viewing jar files:
    jar tf myfirst.jar
    then it will show as below
    META-INF/
    META-INF/MANIFEST.MF
    amir/Hello.class

  4. Running jar file:
    java -jar myfirst.jar
    output:
    Hello its form Hello.java inside amir package