How To Make A Java Jar File
Java Programming For The Absolute Beginner
|
Subjects > ... > Java Programming
Compress Files To A Java Archive (JAR)
This is by far the most common use for JAR files: to compress multiple files into a single JAR archive. JAR files can be opened with WinZip or WinRar?Create. In terms of Java applications, the ability to archive any number of source or class files into one single archive represents the biggest advantage - distributing one file containing hundreds of files is so much easier than distributing hundreds of files separately!
The jar utility program is run from the command line (DOS prompt or bash for example, depending on your OS). Here is how to create a compressed JAR file:
jar cf archive_name.jar filesLet's look at each part of that command line.
jar The command to run the jar utility.
CF Create a new archive with the file name specified. These two options are from this list of common options:
- c create new archive - t list table of contents for archive - x extract named (or all) files from archive - u update existing archive - v generate verbose output on standard output - f specify archive file name - m include manifest information from specified manifest file - 0 store only; use no ZIP compression - M do not create a manifest file for the entries - i generate index information for the specified jar files - C change to the specified directory and include the following file
Multiple options can be used together. They all must appear after the "jar" command with no white space separating them.
archive_name.jar Name of the JAR file. This can only be included if you use the 'f' option.
files Names of all the files you want to put in the jar file. This could be just one name or a list of multiple names separated by space. Names can use pattern matching characters to match multiple files [hospedagem].
Related
Search for books about:
|
Interested in Kay Francis?