Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javatutorial How to use JAR file in Java

Related Tutorials


 
 

Share on Google+Share on Google+

How to use JAR file in Java

Advertisement
To use JAR files in Java, first create a JAR file compressing and archiving all the classes of a program and then execute it wherever and whenever they want. JAR files makes the classes portable.

JAR which stands for Java ARchive allows a programmer to archive or collect all the classes, resources, images, etc at one place so that it becomes easy to run a program.

It makes sure that the files remain secure. For this one has to digitally sign the JAR file. Users who want to use the secured file can check for this signature and know that such files can be trusted and then allow the access needed.

To run a program, a programmer needs lots of classes, if he/she do not use JAR file, then they will have to download every single file one at a time. This makes the work lengthy. But if you have archived all the classes in JAR files, then you just need to download one single file and Run it.

When you are making a JAR file, you are also compressing them for efficient storage.

JAR files also add portability as this file can be downloaded anywhere and run on any platform. All operating system support Java.

JAR file works as normal Zip file. You Zip a number of files i.e. compress and archive them at one and then Unzip them to use it.

Common commands and their operation:

  • Create a JAR file - jar cf jar-file input-file(s)
  • View the contents of a JAR file - jar tf jar-file
  • Extract the contents of a JAR file - jar xf jar-file
  • Extract specific files from a JAR file - jar xf jar-file archived-file(s)

To create a JAR file type "jar cf jar-file input-file(s)" in command prompt. "c" parameter means that you want to create a jar file and "f" parameter means that you want to send the output to a file. .jar extensions are given to JAR file.

To view a JAR file type "jar tf jar-file" in command prompt. "t" parameter means you want to view the table of contents of the JAR file and "f" parameter indicates the JAR file whose contents are to be viewed is specified on the command line.

To extract a JAR file type "jar xf jar-file" in command prompt. "x" parameter means that you want to extract files from the JAR archive and "f" parameter means that the JAR file from which files are to be extracted is specified on the command line.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 21, 2013

Related Tutorials

Discuss: How to use JAR file in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com