Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 3
Next, we extract the jar file's name. First, we ask for a URL to the class file containing the currently running class (which is the extractor program). Once we have the URL, we can snip out the jar file's name. By definition, the URL of the JAR extractor program follows the basic format:
jar:, which shows that the executable runs from inside a jar file
file:/C:/temp/test.jar, followed by the ! character
/ZipSelfExtractor.classIn the extractor program's case, the URL might look like:
jar:file:/home/johnm/test/zipper.jar!/ZipSelfExtractor.class
Now that we have the jar file's name, we can perform the extraction. The guts of the extraction program rely on the built-in, Java zip/jar file manipulation libraries to uncompress the content files contained in the archive. See Resources for more on the zip/jar file manipulation libraries.
For ease of use, the extractor is a graphical Java application. The application uses the JFileChooser class to let users specify the destination directory to which they want the files extracted. A ProgressMonitor shows the progress of the extraction process. If a file might overwrite an already existing file, the user is asked whether
or not to overwrite the existing file. At the conclusion, a standard dialog box presents extraction statistics.
Finally, the extractor program checks that it does not extract the files that make the jar file self-extracting -- the manifest
file and the extractor's .class file; the program should just extract the original JAR contents. Those two files are artifacts of the self-extracting jar
file and not part of the original, base content files.
Now that we have the manifest file and the extractor program, we can build the self-extracting jar file. We can manually use
the JDK's jar utility to make a self-extracting jar file. For example, assuming you have a zip file called myzip.zip, you can perform the following steps to make a self-extracting file from it:
cd to the directory containing myzip.zipzipper.jarjava -jar zipper.jar
zipper.class file to ZipSelfExtractor.classmyzip.zip as myzip.jarmyzip.jar with the jarmanifest and ZipSelfExtractor.class files:
jar uvfm myzip.jar jarmanifest ZipSelfExtractor.class
Now myzip.jar is self-extracting on all platforms containing Java Runtime Environment (JRE) 1.2 or later. To execute the self-extracting
jar file, run:
java -jar myzip.jar
Note that some platforms may have bindings already set up such that you can execute the jar file just by clicking on the myzip.jar file icon, which will run the command line equivalent.
The current ZipSelfExtract does not integrate well if you make a self-extracting JAR out of an existing jar file containing a manifest file. Add intelligence
to the self-extractor and the creation instructions so you can deal with existing jar files that contain manifest files.