The Java bytecode comprising an application is commonly bundled and delivered in the form of a Java Archive (JAR) file.

Here I gonna start how to create JAR File

-open command

-go to ur files & folders destination and compile the java file then

-type:

 jar cvf filename.jar list of files to be included in jar
Output looks like this jar1 For inspection the content of JAR file.
jar tvf jarfilename.jar

for eg. [sourcecode='c']jar tvf final.jar[/sourcecode]

Output looks like this:

jar2

Using Bytecode contained with in a JAR file.

For informing the Java Virtual Machine that we want to use the bytecode of a JAR file, we use a code(command) option to set an environment variable called the classpath:

java –cp path_to_jar_file class_which_contains_main_method

for eg.[sourcecode='c'] java -cp final.jar A[/sourcecode]

Extracting Content of a JAR File

Here we can extract every files of jar file by the following command:

 jar xvf jarfilename.jar list_of_files_for_extracting

for eg.[sourcecode='c']
jar xvf final.jar A.class B.class[/sourcecode]

To extract everything from a JAR file, we’d type:

[sourcecode='c']jar xvf final.jar[/sourcecode]

Jarring Entire Directory Hierarchies

Here we are going to extract all the subfolder and all files of the folder in a single jar file.

jar cvf jarFileName MainDirectoryName

for eg. [sourcecode='c']jar cvf new.jar "C:JavaProject"[/sourcecode]

//don't forget to put quote for the folder directory

jar3