How to create JAR file in Windows


JAR (Java Archive format) is file format to compress files or bundle multiple files into one archive file. Zip is simple archiving and compressing tool but JAR includes a special file called Manifest  which adds versatility to JAR file, and hence provides enhanced functions like versioning, packaging and digital signature.  The following explains a simple procedure to create a JAR file in Mirosoft Windows.

JAR file are created using Java Archive tool which is part of Java SDK. Hence to create a JAR file, SDK needs to be installed on the system.  We will see jar.exe and other binary file in bin folder in Java SDK, as shown below.
(We can see Jarsigner.exe is also part of the Java SDK. It help us create the digitally signed files. )

To create the JAR file in Microsoft Windows we will need to go to the command prompt.

Put all the files that are to be archived in some directory , say c:\test ( say files are b.txt and a)

Go to start menu and select run program. Go to the path where the files are there, here to c:\test

Check where SDK is located in machine.  Check for the jar.exe in bin folder into SDK folder package name. It can be like C:\j2sdk1.4.1_05\bin. Type the path of jar as shown below. Then type the jar command as

jar options xxx.jar file_names

Here,  options here shown are
c -> to create an new archive
v -> It gives the verbose output on standard output. It will give whole details of all the file being added and how much they are deflated.
f -> it specifies the file name of the created JAR

xxx.jar means the name of jar file you want to give for e.g. test.jar

file_names are the input files that are to be archived. Since we want all the files to be archived we have given below the parameter as asterisk (*).

When you run the command you see the following output ( because of –v option)

The jar file test.jar in created in test directory itself.

To unjar  the jar file back to original files you just need to give the following command in the jar file directory, in this example c:\test

C:\java\j2re1.4.1_02\bin\jar -xvf test.jar

Where x is the option to extract files from archive and C:\java\j2re1.4.1_02\bin\ is the JDK installation path.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>