Creating a simple jar archive

From the command line

To create a jar archive from the command line, use this format for the command:
  jar cvf <filename>.jar <list_of_files>
where you substitute your actual filename above, and then a list of the files you want to pack up.

Example:

  jar cvf hw2.jar Class1.java Class2.java File3.java

You can double-check the contents of the above packed jar file with this command:

  jar tvf hw2.jar

In these commands, the c flag stands for "create", and the t flag stands for "table of contents".
 

Creating a jar archive using Eclipse

  1. From the "File" menu, select "Export"
  2. In the window that pops up, click on the + sign next to the "java" folder, then click on "JAR file", and click "Next"
  3. On the next window, you'll be asked to select the resources to export. You can pick resources from multiple projects.
  4. Click "Finish"

To check the contents of the jar file you just created

  1. From the "File" menu, pick "Import"
  2. In the select window that comes up, pick the "General" category, then "Archive File", and click "Next"
  3. Use the "Browse" button to locate your jar file
  4. The window will now show a listing of contents in the right half. Verify that it contains the files you were packing up
  5. You can click "cancel" to get out of this window without actually unpacking the archive. Or you can click "Finish", but this will try to unpack, and it will probably ask if you want to overwrite the source code files in their original locations. You don't need to do this