How to make JAR from Java Source/Class files

You can make executable .JAR files from your java class files. This .jar file is a compressed single file which can be executed from desktop by opening double-clicking!

Fist of all, you need your class files of your program. So if you have three java sources, named, &, First of all go to command-prompt & make classes of the sources.

javac *.java

Assumed that you are running the command from the directory where your class files are located.

Next, we need to let the JAR know what’s the main class of the program. For this, create e text-file (i.e mainclass.txt) & write in the following manner:

Main-Class: they

IMPORTANT: the text file only needs the one line of text for this purpose. However,
the file must end with a blank line or this will not work, ie the file has two lines in it
– the second one is empty. Note too the class is called “they” and not “”
(the file containing the source code) or “they.class” (the file containing the byte
codes). If your class file is in a package hierarchy, you must use the fully qualified
name of the class (eg “myPackage.MyClass”).

Finally, run the jar utility with this command line:
jar cmf mainclass.txt example.jar *.class

That’s it!

Further reading:

Java’s Tutorial on Jar files:
Roedy Green’s JAR file page:

One thought on “How to make JAR from Java Source/Class files

Leave a Reply

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

You are commenting using your 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