Creating
a .jar submission file
jar is a utility provided with the Java Development Kit that allows a programmer to archive/compress many .class files into a single .jar file. Since the java compiler makes a number of .class files when compiling your program, combining these files into a single .jar file makes submission and testing of your program more convenient.
This document will contain only the basics of creating and using .jar files (enough to submit your assignments correctly). For more information on the jar utility, see
http://java.sun.com/docs/books/tutorial/jar/
For the purposes of this handout, I am making the following assumptions:
1) Your .java file that contains your main method is Assig1.java
2) When compiled, this file produces a file called Assig1.class (and potentially other .class files as well)
3) During compilation, other source files may also be compiled into .class files as necessary.
Naturally, you should change
the names to fit your filenames.
To produce a .jar submission file for your program, do the following:
1) Make sure all of your .class files are in the same directory, and that you are currently in that directory.
2) Create (in the same directory) a text file called manifest.txt that contains the single line: Main-Class: Assig1
Make sure you have a CARRIAGE RETURN at the end of this line!
3) Execute the following command from the command prompt:
jar -cvmf manifest.txt
Assig1.jar Assig1.class
where in place of the you put the names of all of your other .class files.
The command means the following:
c means to create a new .jar file
v means to be verbose and show what is happening as the file is created
m means you are including a manifest file (manifest.txt)
f means you are choosing the name of the new .jar file (Assig1.jar)
Make sure you include ALL of your .class files (in place of the ) when you create your .jar file, since your program will not execute correctly otherwise.
Once created, your .jar file can be used to run your program without the original .class files. To test this (so you are sure your program will run for the TA without compilation), do the following:
1) Create your .jar file as specified above
2) Delete all of the .class files for your program
3) Execute the following command
java jar Assig1.jar
If your program does NOT execute with the command above, check to make sure you have created your .jar file correctly (remember to use names specific you your program). If you cannot get your .jar file to work correctly, see me or a TA as soon as possible. If you do not submit a working .jar file with your assignment, you will lose some points!