Monday, 29 April 2013

about jar file in java , create , extract etc

JAR :- Java Archive (JAR) file format enables you to combine multiple files into a single archive file. Jar files are packaged with the ZIP file format.

Benefit of .jar File (Source Oracle) :-
1. Security.
2. Decreased download time.
3. Compression.
4. Package Versioning.
5. Portability etc.

JAR file operations Command :-

To create a JAR file Suppose you have some .class file in your desktop :-

APP-66:~ Arun$ cd Desktop/
APP-66:Desktop Arun$ jar cf ams.jar *.class
APP-66:Desktop Arun$
Now you see own your desktop asm.jar created.

To view the contents of a JAR file:-

APP-66:~ Arun$ jar tf asm.jar
command displays the contents of the JAR file to stdout

To extract the contents of a JAR file:-

APP-66:Desktop Arun$ jar xf ams.jar 
original ams.jar JAR file remains unchanged.And show all containing classes in your desktop and META-INF Folder.

To extract specific files from a JAR file :-
APP-66:Desktop Arun$ jar xf jar-file archived-file(s)

To run an application packaged as a JAR file :-
APP-66:Desktop Arun$ java -jar app.jar

To invoke an applet packaged as a JAR file:-

You Can Extract .jar Using the Following Command:-
(path of your .jar file and after type command) jar xf test.jar