Steps to make a JAR file....

07 January, 2009 | | 0 comments |

Share |
There are innumerable times since many people have posted questions on how to make a JAR file and what it can help in.....So I thought I'll myself help you out.....

You can create JAR files for two things:
1] For packaging together .class files to be used as applets, servlets, JSP or other purposes. Here only .class files have to be included in the JAR file. Here manifest file is not required.
2] For creating console applications(i.e. For applications which have void main() in one of the class files). These applications can be executed by just double-clicking the JAR files(provided JRE is installed). ".class" files along with a manifest file has to be included, in the JAR file.

----------------->To Create Manifest File:
1] Manifest file has two attributes:
---> Manifest-Version: 1.0
---> Main-Class: ABC.class (i.e. this means ABC is the entry class file which has void main())

Other optional attributes are:
---> Created-By: Guru (i.e. Name of the developer)

Include the attributes in notepad and save with .mf extension. Make sure Type of file is "All files" rather then "text file".

========================

----------------->To Create JAR file:
--> Goto DOS prompt and to the location where your .class files are. Make sure 'set path' has been set. Now enter this command to create the JAR file.

jar cvfm mmm jjj 1.class 2.class 3.class

where,
mmm --> Manifest file (mmm.mf)
jjj --> JAR file to be created (jjj.jar)
1.class, 2.class,3.class --> Files to be included into JAR

=======================
Similarly, for Servlets, Applets, JSP or other purposes use the above command:

jar cvf jjj 1.class 2.class 3.class

NOTE: Here manifest file won't come

Example of a console application:

Assuming there's an application with ABC as the main class. 1.class, 2.class and 3.class are the other class files required to run the application....

So the manifest file would look like this:

-------------------- Manifest.mf ---------------------
Manifest-Version: 1.0
Main-Class: ABC.class

JAR file named "PQR" can be created with the command:

jar cvfm Manifest.mf PQR.jar 1.class 2.class 3.class

Example of an Applet, JSP, servlet etc:

All the above steps will be same minus the manifest file and the manifest attribute...


=======================
Guru says Lolz......

0 comments: