JAR File : Java Archive File

Hello friends.

This is one of my tutorials for JAVA learner. All of you must be aware of Java Archive File i.e. JAR file.

Jar file is nothing but the collection of various class files into a single module.

Now one must be thinking that what is the actual need of jar file? Look friends this is not compulsory to create a jar file when we can directly run our code using class file to be interpreted. But what if we want that code to be used by any other person who does not know java or has no knowledge about how to run the java code? In this case we can provide the compressed version of class files into a single module called JAR file. Here in this case user does not have to do anything, he just has to double click the jar file and JVM will do all the remaining things.

For example if we are creating an application which takes input from user in any case (Either Upper or Lower) and the output must be just the opposite of the case inputed, then in such case running the class file each time wont be feel good for the user. So we can create the Jar file so that user don’t have to interpret class file each time.

Creating a jar File in Command Prompt

1) Start Command Prompt.

2) Navigate to the folder that holds your class files:

C:>JavaPrograms myworks

3) Set path to include JDK’s bin. (Ignore this if you have already set the path in Environmental Variables) For example:

C:JavaProgramsmywork> set path c:Program FilesJavajdk1.6.0_09bin;

This will set the Path.

4) Compile your classes just like we compile any other classes. Make sure that all the classes are compiled to avoid any Error.

5) Create a jar file:

C:JavaProgramsmywork> jar cf MyJar.jar  *.class  [<- This will include all the class files in the folder->]

C:JavaProgramsmywork> jar cf MyJar.jar .class files [<- Manually select the class files ->]

6) Then test your jar file using  java.exe as follows:

C:JavaProgramsmywork>java  MyJar.jar

This is all about Creating Java Archive Files, But what if I want to Modify, View Contents or Extract Contents from the Jar file. Following might help you in this.

1) View contents of a JAR file

C:JavaProgramsmywork>jar tf MyJar.jar

2) View contents with detail of a JAR file

C:JavaProgramsmywork>jar  tvf MyJar.jar

Note that we have used v (verbose) option to see the detail of JAR such as Date time etc.

3) Extract content of JAR file

C:JavaProgramsmywork>jar xf MyJar.jar

This will Extract all the files from the Current jar file.

4) Extract specific file from JAR file

C:JavaProgramsmywork>jar xf MyJar.jar Filename.class

5) Update a JAR file

C:JavaProgramsmywork>jar uf MyJar.jar addFile.class

Here addFile.class is any class file that we want to add to the MyJar.jar file

You can add more than one class files to the Existing jar file by placing them between White spaces.

ThankYou.

Regards-

Nikhil Naoghare.

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Maven Installation.

    Hello Friends, This is one of my tutorial for installation of Maven on windows. Maven is a software project management tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is an open source community and is a…

  • Jira Plugin Deployment.

    Hello Friends, This is one of the most important tutorial for all the jira developers. You may have heard about the plugins in jira which is a simple Java Archive File with .jar extension. This JAR file contains the class files and auxiliary resources associated with the applications. In Jira we can use Eclipse IDE…

  • Java Date Format.

    Hello Friends, This is one of my tutorials regarding java Date format / object in Java. Many of us find it difficult to store the current date from the java application in database. Lets consider MySql as a database in this case. Now when we create a row in the database table that stores date…

3 Comments

  1. Mary, I agree with your comment, this issues is a big deal but the book ‘tree house’ can help you understand the difference.

  2. hello
    i want to developp a jira plugin of migration
    and which consists in adding an interface in JIRA
    button ,browse ..
    the user can thus browse an excel file ;to convert it in a csv File (i have yet implemented the converter as a java class) and then to apply csv importer on this csv file
    would you please help me?can you provide me with tutoriels or ideas to perform this?or can i have a similar sample plugin with delailled steps of this?
    i’m really in urgent need (please send me your response by email)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.