Friday, June 5, 2009

Creating Jar file (Java executables) - Very simple

Step 1:
Create a Hello.java class .
public class Hello{
public static void main(String args[]){
System.out.println("welcome to Java’s chronicle");
}
}

Step-2 :
Compile the above java file.

Cmd > javac Hello.java

Step- 3:
Create a mainClass.txt with the following contents

Main-Class: Hello

Note :
Remember the above must be terminated with carriage return coz some of the OS expects CR to create Manifest file.

Step- 4:
Go to command prompt create jar file

Cmd > jar -cvmf mainClass.txt my1.jar Hello.class
success :
added manifest
adding: Hello.class(in = 411) (out= 282)(deflated 31%)

where :
c-create jar

v-verbose
m-mainclassfile

Step 5:
To list the contents of jar

Cmd > jar tf my1.jar

META-INF/
META-INF/MANIFEST.MF
Hello.class

Step 6:
To Execute jar

Cmd > java –jar my1.jar

I just tried explaining in a layman terminology ...Hope it is useful
Further any queries kindly get back to me......

Keep Rocking
Shyamala

No comments:

Post a Comment