|
|
Saturday, August 31, 2002 |
|
expanding jar files jar -xf foo.jar
You can create the hw0.jar file by using the following command:
The "jar" program is a utility that creates and unpacks Java archive files. The "c" option indicates that we want to create a new Java archive. The "f" option specifies that we want the Java archive to be created into the file named "hw0.jar". The remaining arguments on the command line give the names of the source files to put into the archive. One very common error is to do the following: Try typing in the following command (but don't do it if you haven't already created hw0.jar using the command above first):
What has happened here is that the Java archive file has been created and put into a file named Hello.java. This effectively has deleted your Hello.java file!. As you can see, the first parameter to the jar command is the name of the jar file, and the remaining parameters are the files to put in it. You must be very very very careful when creating your Java archive file, because if you accidentally delete one of your java files, it's impossible to get it back. Luckily, in this case we have already created a good archive in hw0.jar, so we can restore our Hello.java file simply by unpacking the archive:
More Detailed notes on using JAR 6:13:08 PM |