Skip to content
January 31, 2009 / Narayan

Jar Archive File

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

 for eg. jar cvf final.jar A.class B.class

   or alternatively jar cvf final.jar *.class

Output looks like this


jar1

For inspection the content of JAR file.

 jar tvf jarfilename.jar

   for eg.  jar tvf final.jar

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. java -cp final.jar A

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. jar xvf final.jar A.class B.class

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

      jar xvf final.jar

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. jar cvf new.jar "C:JavaProject"

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

jar3

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: