A JAR file is basically a special ZIP file. JARs are commonly used to bundle Java classes together into a single file that you can then easily transfer, execute, or digitally sign. Since the jar
tool comes with the JDK, everyone in 211 will have access to it regardless of platform. So we'll use JAR as a standard format to bundle multiple files together for Tamarin submission.
Open a command prompt and navigate to the directory containing your .java source files. Then type a command something like this:
jar vcf UsernameA06a.jar Node.java Stack.java PyramidStack.java UsernameA05a.java
jar
is the name of the program. The next argument gives 3 options: v, which will produce verbose output, c with creates a new jar, and f, which creates a file rather than printing to standard out. The next argument is the name of the .jar file you want to create. The remaining arguments are the files you want to add to the new jar.
If the .java files in the current directory are only those for the current assignment, you can shorten the above to:
jar vcf UsernameA06a.jar *.java
which will bundle all .java files in the current directory. The verbose output will let you see exactly what got added.
If you're submitting to Tamarin, you only need to include your .java files, as described above. If you are creating a jar file for distribution, though, then you would need to include your .class files. Also, you can specify which class should be executed when the jar is executed. For example:
java vcfe UsernameA06a.jar UsernameA06a *.class *.java
The extra e
option means you need to specify the name of the class to run when the jar is executed. If you don't want to include your source code, leave off the *.java.
To execute this jar, you'd use:
java -jar UsernameA06a.jar
To see a usage message listing all the jar
tool options, run jar
with no arguments.
Your IDE may be able to create JAR files for you. However, note that the normal use of a JAR file is to distribute .class files. For submitting to Tamarin, you must also include your .java files. If you can't figure out how to make your IDE include the .java files too, then use the command line as shown above. If you need to configure your PATH to do this, you may want to revisit the A00 FAQs.
For more information about what else you can do with JAR files, see the tutorial.