Home > Articles

  • Print
  • + Share This
This chapter is from the book

JAR File

When you're ready to submit your project, you will upload one JAR file containing everything in your project. To create an archive JAR file from multiple files, you need to use the jar utility. The file generated by the jar archiving tool is based on the ZIP and ZLIB compression formats. The following is a common example of the jar tool creating a file named certificationJarFile that contains all the class files in the current directory:

jar cf certificationJarFile.jar *.class

Sun's instructions tell you what to name the JAR file, so use that name, not the one you see in these examples; you lose points if you use a different filename. For my solution, I used the following command (my.jar was the JAR filename I was given in Sun's instructions):

jar cfv my.jar *

If you issue this command from your project's root directory, assuming it is the same one shown previously, all the class files in the application package are added, including the server, client, and database directories. This command also adds all the source directories, which mimic the class directories, and grabs all the javadoc files and loose files in the root directory.


Another simple option is going to the parent directory of the install directory and using jar cvf myFile.jar ./INSTALL_DIRECTORY. (Note that the path separator is \ for Windows.)

These are the most common options for the jar tool:

  • c—Creates a new JAR file.

  • t—Prints the table of contents.

  • f—Names the JAR file to create or open.

  • v—Generates verbose output.

  • x—Extracts all, or only named, files.


Your solution must be in a single JAR file. Before you upload that JAR file, extract it, check that all files are present and useable (open the README.TXT file), and run your application. Make sure the source code is present after you extract the JAR file.

Some people nest JAR files and even use executable JAR files. Both approaches are fine. I chose to make it simple for the evaluator by not nesting JAR files, not using executable JARs, and placing the README.TXT and design decisions files in the root directory. Introducing points of possible failure in this structure isn't desirable, so keep it as simple and reliable as possible. You get no additional points for complexity.

  • + Share This
  • 🔖 Save To Your Account