Unpack the jar package
Jar XF Xxx.jar
packaged as a jar packageMethod One: Through the jar command
Use of the jar command:
The following is a help description for the jar command:
Usage: jar {ctxui}[vfm0me] [jar-file] [manifest-file] [entry-point] [-c dir] files ...
Options include:
-c Create a new archive file
-t list archive directories
-x Unzip an archived specified (or all) file
-u Update an existing archive
-v generate verbose output in standard output
-f Specify the archive file name
-m contains inventory information from the specified manifest file
-e For standalone applications bundled into executable jar files
Specify application entry point
-0 store only ; Do not use any ZIP compression
-M do not create an entry manifest file
-i Generate index information for the specified jar file
-C change to the specified directory and include the file in it
The specified order of the manifest file name, the archive file name, and the entry name
is the same as the specified order for the "M", "F", and "E" flags.
Example 1: Archive two class files into an archive named Classes.jar:
Jar CVF Classes.jar Foo.class bar.class
Example 2: Use the existing manifest file "Mymanifest" and
Archive all files in the foo/directory to "Classes.jar":
Jar CVFM Classes.jar mymanifest-c foo/.
The following assumes that the compiled class file is in the bin directory
One, packaged into a generic jar package
Enter the following command:
Jar CVF Counter.jar-c bin.
Where the "-C bin" is actually telling the jar command to first CD to the bin directory, and then execute the command with no parameter "-C bin" in this directory, equivalent to:
CD bin
Jar CVF Counter.jar. // "." Represents the current path
Second, packaged into a runnable jar package
To package as a runnable jar, there are two ways to create a MANIFEST.MF file manually, specify the main class in it, and use the-e parameter of the jar to specify the entry point to run the jar package (that is, the full name of the main class).
As an example of how to package Java source code line count programs, show how to package:
1. Manually create the MANIFEST.MF file:
1) First edit the MANIFEST.MF file with the following content:
Manifest-version: 1.0
Created-by:rsljdkt
Class-path:.
Main-class:main
Description
The first line specifies the version of the manifest, and if none, the JDK default build: manifest-version:1.0
The second line indicates the created author, and if none, the JDK generates CREATED-BY:1.6.0_22 by default (Sun Microsystems INC).
The third line specifies the classpath of the main class.
Row four indicates the main class that the program is running
2) package using the jar command:
Jar CVFM Counter.jar MANIFEST. Mf-c bin.
Description
Parameter f: Specifies the package name after packaging.
Parameter m: Specifies a custom MANIFEST.MF manifest file, otherwise the JDK automatically generates a default manifest that does not contain main-class.
Parameter C: Specifies that a new archive file is created.
Parameter V: generates verbose output in standard output, which is optional.
2. Specify the entry point using the-e parameter:
Execute the following command:
Jar Cvfe Counter.jar Main-c bin.
Method Two: Use the export feature of Eclipse:
One, packaged into a generic jar package:
The steps are as follows:
1) Right-click on the item you want to package, select Export
2) in the pop-up window, select Java-Jarfile, then click the Next button
3) in the Jar filespecification window, set the file name and location of the package, click on both sides next
4) in the Jar manifestspecification window, set the configuration of the MANIFEST.MF manifest file,
If only packaged into a simple jar package, do not make any changes, take the default can
If packaged as an executable jar package, you can use an existing manifest file or select the main class directly
5) Click the Finish button to complete the package.
Second, packaged into a runnable jar package
The steps are as follows:
1) Right-click on the item you want to package, select Export
2) in the pop-up window, select Java->runnable JAR File and click the Next button
3) in the Runnable JAR filespecification window, select Launch configuration and export destination
4) Click the Finish button to complete the package.
[Java] Java packaged into jar package and decompression jar package