Tuesday, March 22, 2011

Creating an Executable jar File



Creating an Executable jar File
Here I am going to explain you how to make jar file from class file in java.
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: IT Martial
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.
Once you have a manifest and all your classes have been compiled, you need to run JDK’s jar.exeutility. It is located in the JDK’s bin folder, the same place where javac.exe and java.exe. are. jar.exe takes command-line arguments; if you run it without any arguments, it will display the usage information and examples. You need
C\martial> jar cvfm JarName.jar manifest.txt *.class
cvfm means "create a jar; show verbose output; specify the output jar file name; specify the manifest file name." This is followed by the name you wish to give to your jar file, the name of your manifest file, and the list of .class files that you want included in the jar. *.class means all class files in the current directory.
Below are the detailed steps for doing this in Command Prompt.
Creating a jar File in Command Prompt
1. Start Command Prompt.
2. Navigate to the folder that holds your class files:
C:\>cd \martial
3. Set path to include JDK’s bin. For example:
C:\martial> path c:\Program Files\Java\jdk1.5.0_09\bin;%path%
4. Compile your class(es):
C:\martial> javac *.java
5. Create a manifest file:
C:\martial> echo Main-Class: IT Martial >manifest.txt
6. Create a jar file:
C:\martial> jar cvfm IT Martial.jar manifest.txt *.class
7. Test your jar:
C:\martial> IT Martial.jar

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews