Generate an executable jar File

Source: Internet
Author: User
The tutorial for generating executable jar files-Linux general technology-Linux programming and kernel information. The following is a detailed description. To generate an executable jar file named cal. jar: (the file name can be any legal name)
(I think this is a simple and practical method, and there are many other methods that will not be introduced here)
First, put all the bytecode files (namely. class files) generated by the program in the same directory (such as: D:/chat /).
Second, create a new manifest. mf file in this directory. The file content format is as follows (underlined content ):
Format in the manifest. mf file:
--------------------------------
Main-Class: calDemo

--------------------------------
Note: calDemo indicates the name of the main class (that is, the name of the class to be run, which can only be one, not the file extension)
The Main and Class are not underlined
Main-Class: there must be spaces in the middle of calDemo
Main-Class: After calDemo, you must press ENTER


You can also add some other information to the file, such as: (do not add first to avoid errors)

--------------------------------------------
Manifest-Version: 1.0
Created-By: 1.4.1 _ 02 (Sun Microsystems Inc .)
--------------------------------------------

Then use the jar command to generate an executable jar file, for example:
(Go to the Directory D:/chat/before executing this command /)
Jar cvfm cal. jar manifest. mf *. class

Jar usage: (for reference only. skip this part for beginners)
Jar {ctxu} [vfm0Mi] [jar-file] [manifest-file] [-C Directory] File Name...
Option:
-C. Create a new archive
-T list the archived content
-X expand the named (or all) files in the archive
-U: update an existing archive
-V generates detailed output to the standard output
-F specifies the archive file name
-M contains the marker information from the specified file.
-0 storage only; ZIP compression format not used
-M does not generate a manifest file for all items
-I generates 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 is recursively processed.
Both the configuration (manifest) file name and the archive file name must be specified, in the same order specified by the 'M' and 'F' signs.

Example 1: Archive two class files to an archive file named 'classes. jar:
Jar cvf classes. jar Foo. class Bar. class
Example 2: use an existing manifest file 'mymanifest'
Archive the file to an archive file named 'classes. jar:
Jar cvfm classes. jar mymanifest-C foo /.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.