Tuesday 31 January 2012

Steps to create JAR files

All java programmers wonder how they can release their codes. It is advised not to release the source code but the application. But to create the application it is necessary to create an Executable JAR files. All Java enabled mobile phone users are well aware of the fact that all phone apps and games are installed from JAR files.
Now what is this JAR ? It is nothing but short form of Java ARchive.
Contents of a JAR -->
1 : It contains all the class files of your project which were generated by compiling your source code.
2 : It contains a MANIFEST file.
3 : All other files and folders that are necessary for running your project. For example an Images folder that contains images.
Now what is this MANIFEST file ? It is a simple text file that defines which class has the main method. With this definition only the project will be able to load or start the particular class file.
How to create MANIFEST file ? Open a text editor and type Main-Class:classname and press Enter and Save in a file named manifest.txt. For example --> Main-Class:StartUp
After you have all class files, folders and manifest files, follow these bsteps -->
1 : Go to Start>Run. Type cmd and press Enter.
2 : If your path is already set then go to your project directory using cd command.
3 : Use jar tool now to create jar file. Type jar -cvmf <jar file name> <manifest file name> <*.class> <all other files and folders sepearated by space> and press Enter. For example -->  jar -cvmf App.jar manifest.txt *.class Images
What does cvmf means ? the details of each letter is given below -->
c : stands for create JAR file
v : stands for verbose
m : stands for manifest
f : stands for files and folders

No comments:

Post a Comment