Add to Google Reader or Homepage

how to make a jar file

What is a jar file?


The java Archive (JAR) File is used to pack the application which is to be deployed along with its resources.It is similar to .ZIP package format.In this post i will show you how to create a jar file, and how to modify an existing jar file.

Creating a JAR file


The general syntax for creating a jar file is 

jar options JARfilename.jar  file1 file2


Here the most commonly used options are "cvf" altogether or you can use simply "cf"  to create a jar file . Let us have a look at those options to understand what they imply.

Here.

 c - is used to create an empty archive file and add files into it.

 v - is used to generate the verbose output(displays what files are added in to the JAR)

 f  - If you do not use this option then the output will be generated in the console instead 
       of producing a desired java Archive file.

Example:

 

C:\>jar cvf Add.jar Add.class
added manifest
adding: Add.class(in = 1450) (out= 872)(deflated 39%).

As you see by default a manifest  file would be added to the META-INF  directory of the jar file.This Manifest file contains a description about the jar file like Manifest-Version,and created-by in header-fields format.

If you do not want a Manifest file then you can avoid it by including "M" option while creating a jar file like as follows:

Example:  

 

C:\blog>jar cvfM Add.jar Add.class
adding: Add.class(in = 1450) (out= 872)(deflated 39%)

 

Updating a jar file:

Updating an existing jar file is simply done by using the option u instead of c which is used in creating a jar file.

 

Example:

 

C:\blog>jar ufv Add.jar B.class
adding: B.class(in = 480) (out= 333)(deflated 30%)




 
java errors and exceptions © 2010 | Designed by Chica Blogger | Back to top