How to create JAR file in Windows

2009 August 20
by coeditor

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. )

3840221510 b2173d8132 o How to create JAR file in Windows

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)

3840221576 7d49a98b74 o How to create JAR file in Windows

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

3840221620 a8ee269ec2 o How to create JAR file in Windows

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

3840221656 63d5e72de1 o How to create JAR file in Windows

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)

3840221706 1f86a14c57 o How to create JAR file in Windows

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

3839432389 578ce38a43 o How to create JAR file in Windows

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
3839432421 a2e5363894 o How to create JAR file in Windows

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

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS