How to Package/run the jar package and generate EXE files

Source: Internet
Author: User

about how to package/Run the jar package, and generate EXE files. Before a variety of inquiries, blogs, finally find out exactly what happened. I remember taking notes. Today to package generation EXE with the time, incredibly forget how. To check the previous notes, it was not found (as if it had been deleted). decided to write it down so that it can be called at any time.

One, jar package

What is a jar package? The jar package is (Java Archive file), which is the Java archive. The only difference between a jar file and a ZIP file is that it contains a meta-inf/manifest in the contents of the jar file. MF file, this file is created automatically when the JAR file is generated. Jars are divided into: generic jar packages and executable jar packages.

Second, how to package into a jar package

  ① using Eclipse for packaging

1. Select the project you want to package-right-click Export

  

2. Export as generic jar package and executable jar package

② Use the command to package the jar package (the Java environment is configured, you can enter the jar directly in the console to view the command Help)

Packaged as a generic jar package

1) programs written using Eclipse: Class file in the bin directory, SRC is the source file.

Step: Run cmd in the project directory, enter the command: Jar cvf jarpackagename.jar-c bin.

The jar package file is generated under the project directory.

2) the Compiled. class file, which is written using the editor, is packaged according to the directory, and if single or multiple class files

Step: Run cmd in the class file directory, enter the command: Jar CVF Jarpackagename.jar No1.class no2.class

Packaged as an executable jar package

1) programs written with Eclipse: The exported executable jar does not need to be modified to run the jar package directly.

2) a compiled. class file that is written using the editor.

Step: Create the Manifest.mf file, write it down in the file format

manifest-version:1.0
CREATED-BY:1.6.0_22 (Sun Microsystems Inc.)
Class-path:.
Main-class:mianclass

Manifest-version refers to the manifest version, which is generated by default manifest-version:1.0

Created-by refers to the creation of the author, which is generated by default CREATED-BY:1.6.0_22 (Sun Microsystems Inc.)

Class-path refers to the path where the main class resides

Main-class refers to the class of the main class of the program Main method.

Note: the difference between the generic jar package and the executable jar generated by Eclipse is that the MANIFEST.MF file in the generic jar package does not specify Main-class, and the executable jar package is contained.

You must specify Main-class in the executable jar package, otherwise you will be prompted that there is no master manifest attribute in the jar package.

How to Package/run the jar package and generate EXE files

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.