Amazon

Thursday 14 July 2011

How to create an executable jar file

In java, you can create a combine archive for all classes of a project in a jar file. jar files are created using the jar.exe utility program from JDK.  You can make your jar file runnable by telling jar.exe which class has main.  To do that, you first need to create a manifest file.  A manifest is a one-line text file with a "Main-Class" directive.  For example: 
Main-Class: MainClass
This line must end with a newline.


You can create a manifest file in any text editor, or even by using the MS-DOS echo command. You can give your manifest file any name, but it’s better to use something standard, such as manifest.txt.  


use this command to create a jar file.


C\myjavafiles> jar cvfm JarName.jar manifest.txt *.class


Now you can run this java executable as an exe file. Simply double click on thi jar will execute the program.