Take the Test.java under the org directory as an example:
1. Open the command line so that the current directory is ORG, then compile TEST.JAVA files: javac -d. Test.java
The result will generate a TEST folder under ORG.
3. Enclose a text file in the org directory, the content is as follows:
Manifest-Version: 1.0
Created-by: 1.4.2 (Sun Microsystems Inc.)
Main-class: test.test
Save as a manifest.mf file
4. In the command line, use the command: jar -cvfm helloworld.jar manifest.mf test
The result will generate a new.jar file under the ORG folder.
It should be noted:
(1) Main-class corresponds to the public class name (including the package name)
(2) JAR's parameters can be viewed directly with JAR, and details will not be described here.
Test.java source program:
Package test;
Import javax.swing. *;
Public Class Test
{
Public static void main (string [] args)
{
JFrame JF = New Jframe ("Welcome");
Jf.setsize (600, 500);
Jf.setvisible (TRUE);
Jf.setDefaultCloseOperation (jframe.exit_on_close);
}
}
An additional JAR use help:
C: /> jar
Usage: jar {ctxu} [vfm0mi] [jar- file] [manifest- file] [-c directory] file name ...
Option:
-c Create a new archive
-t lists the list of archived content
-x Expand Named (or all) files in the archive
-u Update existing archive
-v generation detailed output to standard output
-f specified archive file name
-m includes indicated information from the indicated file
-0 storage mode; unused zip compression format
-M does not generate a list of all items (Manifest] file
-i generate index information for the specified JAR file
-C changes to the specified directory and contains the following files:
If a file name is a directory, it will be processed.
The list (Manifest) file name and archive file name need to be specified, press the same order as specified by 'm' and 'f' flags.
Example 1: Archive two Class files into an archive file called 'classes.jar':
Jar cvf classes.jar foo.class bar.class
Example 2: Use an existing list (Manifest) file 'mymanifest' All Foo / Directory All
The file archive into a archive file called 'classes.jar':
JAR CVFM Classes.jar mymanifest -c foo /.