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:
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
-
Creating mainclass file:
mainclass contains below line
Main-Class: amir.Hello -
Making jar files:
jar cmf mainclass myfirst.jar amir/Hello.class
then u will get myfirst.jar -
Viewing jar files:
jar tf myfirst.jar
then it will show as below
META-INF/
META-INF/MANIFEST.MF
amir/Hello.class -
Running jar file:
java -jar myfirst.jar
output:
Hello its form Hello.java inside amir package